Find check constraints given Table and Column

Find check constraints given Table and Column

Post by Jim Elde » Sat, 16 Mar 2002 03:48:42



How do I find the name of a check constraint given a Table Name and a Column
Name?

I need this to work on SQL 7 and 2000.

Thanks!
Jim

 
 
 

Find check constraints given Table and Column

Post by oj » Sat, 16 Mar 2002 04:00:06


jim,

use info views...

select *
from information_schema.table_constraints
where table_name='tb'

--
-oj
Rac v2.0 is coming...
http://rac4sql.home.attbi.com


> How do I find the name of a check constraint given a Table Name and a
Column
> Name?

> I need this to work on SQL 7 and 2000.

> Thanks!
> Jim


 
 
 

Find check constraints given Table and Column

Post by Jim Elde » Sat, 16 Mar 2002 04:15:38


oj,

Thanks for the quick response.    The constraint I am looking for is a
column constraint
not a table constraint.

It is not listed in information_schema.table_constraints.

I considered information_schema.check_constraints but
unfortunately the Table Name and Column Name is not also
listed in information_schema.check_constraints.

Do you have any other suggestion?

Thanks!
Jim


> jim,

> use info views...

> select *
> from information_schema.table_constraints
> where table_name='tb'

> --
> -oj
> Rac v2.0 is coming...
> http://rac4sql.home.attbi.com


> > How do I find the name of a check constraint given a Table Name and a
> Column
> > Name?

> > I need this to work on SQL 7 and 2000.

> > Thanks!
> > Jim

 
 
 

Find check constraints given Table and Column

Post by oj » Sat, 16 Mar 2002 04:25:33


jim,

table_constraints contains all constraints in the db...

select *
from information_schema.table_constraints
where constraint_type='check'

will give you the same list as check_constraints.

--
-oj
Rac v2.0 is coming...
http://rac4sql.home.attbi.com


> oj,

> Thanks for the quick response.    The constraint I am looking for is a
> column constraint
> not a table constraint.

> It is not listed in information_schema.table_constraints.

> I considered information_schema.check_constraints but
> unfortunately the Table Name and Column Name is not also
> listed in information_schema.check_constraints.

> Do you have any other suggestion?

> Thanks!
> Jim



> > jim,

> > use info views...

> > select *
> > from information_schema.table_constraints
> > where table_name='tb'

> > --
> > -oj
> > Rac v2.0 is coming...
> > http://rac4sql.home.attbi.com


> > > How do I find the name of a check constraint given a Table Name and a
> > Column
> > > Name?

> > > I need this to work on SQL 7 and 2000.

> > > Thanks!
> > > Jim

 
 
 

Find check constraints given Table and Column

Post by Jim Elde » Sat, 16 Mar 2002 04:33:21


oj,

Quote:> table_constraints contains all constraints in the db...

Sorry, my mistake.

All I need now to solve this is to get the constraint, table,
and column in one view...  It's just the column name that's
missing.

Thanks so much,
Jim

 
 
 

Find check constraints given Table and Column

Post by Jim Elde » Sat, 16 Mar 2002 05:03:56


Thank you again for your guidance.

The solution is not so pretty but it works for me

CREATE PROCEDURE sp_KillCheckConstraint


AS
BEGIN


(SELECT C.CONSTRAINT_NAME
 FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS C
 LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS T
   ON C.CONSTRAINT_NAME = T.CONSTRAINT_NAME

 WHERE T.CONSTRAINT_TYPE='CHECK'



END

-Jim

 
 
 

Find check constraints given Table and Column

Post by Jim Elde » Sat, 16 Mar 2002 05:55:35


Correction:

CREATE PROCEDURE sp_KillCheckConstraint


AS
BEGIN


(SELECT C.CONSTRAINT_NAME
 FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS C
 LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS T
   ON C.CONSTRAINT_NAME = T.CONSTRAINT_NAME

 WHERE T.CONSTRAINT_TYPE='CHECK'



END

 
 
 

1. Change table check constraint to column check constraint?

After our SQL 6.5 database was wiz'd into SQL 7.0 format, I noticed that many
(but not all) of the column check constraints were converted to table check
constraints.  These really are simple data-entry checks, and logically belong
with the column.

Is there a way to convert them back to column check constraints without
having to recreate the table?  I can't find any syntax in ALTER TABLE to add
a column check constraint.

Why do I care?  It's either change the ERWin schema or fix the database, and
frankly, I think ERWin is right this time.

TIA
--
Bobb Head

Sent via Deja.com http://www.deja.com/
Before you buy.

2. FREE PAGERS! LOOK HERE! NO STRINGS!

3. Column check constraint vs table check constraint

4. New Bug! Access 95/VB5/DAO3.5 Date Incrementing bad rounding

5. Table level column reference problem in Check constraint

6. What's causing query to fire?

7. Problem with Alter Table Constraint NO CHECK/CHECK?

8. NY -Colton-ORACLE MANIA- TB

9. Table constraints vs column constraints

10. Table constraints and Column constraints

11. Changing a table-level constraint to a column-specific constraint

12. Could not find CHECK constraint??

13. NOT NULL restriction and CHECK constraint on same column in 7.3.4