Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqldev80
Yak Posting Veteran
68 Posts |
Posted - 2006-06-15 : 11:05:00
|
| query to find out tables in database which do not have any primary key assigned to them |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-15 : 11:21:59
|
[code]select o.name as table_namefrom sysobjects o left join sysobjects k on o.id = k.parent_obj and k.xtype = 'PK'where o.xtype = 'U'and k.name is null[/code] KH |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-06-15 : 12:27:25
|
| [code]print 'Get tables without Primary Keys'select a.TABLE_SCHEMA, a.TABLE_NAMEfrom INFORMATION_SCHEMA.TABLES a left join INFORMATION_SCHEMA.TABLE_CONSTRAINTS b on a.TABLE_SCHEMA = b.TABLE_SCHEMA and a.TABLE_NAME = b.TABLE_NAME and a.TABLE_TYPE = 'BASE TABLE' and b.CONSTRAINT_TYPE = 'PRIMARY KEY'WHERE b.TABLE_SCHEMA is null and b.TABLE_NAME is nullorder by a.TABLE_SCHEMA, a.TABLE_NAME[/code]CODO ERGO SUM |
 |
|
|
|
|
|