Hi
Does anyone know how to generate a list of tables' primary keys, for all tables in a database? Is there a stored procedure or similar
Thanks
Mattuse database
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
Ana
"Matt" <m.barr@.rsamd.ac.uk> wrote in message
news:7F785B2D-D9D3-4848-B336-8789264BABEB@.microsoft.com...
> Hi,
> Does anyone know how to generate a list of tables' primary keys, for all
tables in a database? Is there a stored procedure or similar?
> Thanks,
> Matt|||Matt,
use pubs
go
select tc.TABLE_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS as tc
join INFORMATION_SCHEMA.KEY_COLUMN_USAGE as kcu
on (tc.TABLE_SCHEMA = kcu.TABLE_SCHEMA and
tc.TABLE_NAME = kcu.TABLE_NAME and
tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME)
where tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
order by tc.TABLE_NAME, kcu.ORDINAL_POSITION
Chief Tenaya
"Matt" <m.barr@.rsamd.ac.uk> wrote in message
news:7F785B2D-D9D3-4848-B336-8789264BABEB@.microsoft.com...
> Hi,
> Does anyone know how to generate a list of tables' primary keys, for all
tables in a database? Is there a stored procedure or similar?
> Thanks,
> Matt|||Hi,
Execute the query from the database you require the primary key details;
select * from information_schema.table_constraints where
constraint_type='Primary Key'
Thanks
Hari
MCDBA
"Matt" <m.barr@.rsamd.ac.uk> wrote in message
news:7F785B2D-D9D3-4848-B336-8789264BABEB@.microsoft.com...
> Hi,
> Does anyone know how to generate a list of tables' primary keys, for all
tables in a database? Is there a stored procedure or similar?
> Thanks,
> Matt
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment