what kind of query can I use to determine if a column participates as
a primary/foreign key in a table.
Many thanks and seasons greetings.
Many thanks and seasons greetings.
--checking primary key
if exists
(SELECT b.TABLE_NAME, b.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS a
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE b
ON a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
and b.column_name = <column_name>
and b.table_name = < table_name>)
print 'primary key exists'
--checking foreign key
if exists
(SELECT b.TABLE_NAME, b.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS a
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE b
ON a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
and b.column_name = <column_name>
and b.table_name = < table_name>)
print 'foreign key exists'
--
- Vishal
1. foreign key w/o foreign/primary key
Does anyone have an opinion on the most efficient way to check
referential integrity on a table where the would-be foreign key is
neither unique or primary? Would I use a check constraint? If so, how
without a subquery?
Thanks in advance,
Sent via Deja.com
http://www.deja.com/
2. Changing colors in list box for different records
3. Foreign Key as subset of Primary Key
4. grid
5. One FOREIGN KEY refrences a Table with two Primary Keys
6. Linux Oracle Library Problem...
7. Copying Primary Key to Foreign Key
9. Changing Primary Key Values when foreign key constraints exist
10. delete primary key records together with the foreign keys records
11. Replication with Primary Keys & Foreign Keys Schema
12. Foreign Key and Primary Key Programatic retrieval
13. Update primary key & Foreign key