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 |
|
learntsql
524 Posts |
Posted - 2011-01-10 : 00:31:48
|
| Hi All,I have to find out the missing Primary keys and foreign keys for respected tables for whole database.Please tell me what is the best process to follow?TIA. |
|
|
RobertKaucher
Posting Yak Master
169 Posts |
Posted - 2011-01-10 : 10:10:27
|
LearnTSQL, are you saying you need to find tables that do not have primary keys? If all you are looking for is the heap tables you can query sys.indexes and sys.objects. This example will show the tables and the schema in which they reside that are "heaps".USE MyDBGOSELECT SCHEMA_NAME(o.schema_id) AS "Schema Name" ,OBJECT_NAME(i.object_id ) AS "Table Name"FROM sys.indexes i INNER JOIN sys.objects o ON i.object_id = o.object_idWHERE i.type_desc = 'HEAP' You may also want to see :http://msdn.microsoft.com/en-us/library/ms175068.aspxhttp://msdn.microsoft.com/en-us/library/ms186301.aspx===http://www.ElementalSQL.com/ |
 |
|
|
learntsql
524 Posts |
Posted - 2011-01-11 : 05:53:48
|
| Thanks RobertKaucher,Yea I want to find out missing primary keys and bit more intelligently IS IT possible to find out the respected foreign keys.Please guide me.TIA. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|