Re: how to find out if there is any primary key in each table
From: Aaron [SQL Server MVP] (ten.xoc_at_dnartreb.noraa)
Date: 07/07/04
- Next message: Jacco Schalkwijk: "Re: how to find out if there is any primary key in each table"
- Previous message: queryzator: "Re: problem with sort numbers ..."
- In reply to: sms1: "how to find out if there is any primary key in each table"
- Next in thread: Jacco Schalkwijk: "Re: how to find out if there is any primary key in each table"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 7 Jul 2004 12:59:20 -0400
This query will return only those tables that do not have a primary key.
SELECT t.TABLE_SCHEMA + '.' + t.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES t
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
ON c.TABLE_NAME = t.TABLE_NAME
AND c.CONSTRAINT_TYPE = 'PRIMARY KEY'
WHERE c.TABLE_NAME IS NULL
AND OBJECTPROPERTY(OBJECT_ID(t.TABLE_SCHEMA+'.'+t.TABLE_NAME),
'IsMsShipped')=0
-- http://www.aspfaq.com/ (Reverse address to reply.) "sms1" <sms1@pctc.com> wrote in message news:2QVGc.31$KF.196@tor-nn1.netcom.ca... > Gurus, > > I need to make sure each table (about 500) has one or more primary key. I > plan to write an osql script. > > Question: > What is the command / stored procedure that will tell such information in > sql statement. > > Any help is much appreciated. > > Jenson > >
- Next message: Jacco Schalkwijk: "Re: how to find out if there is any primary key in each table"
- Previous message: queryzator: "Re: problem with sort numbers ..."
- In reply to: sms1: "how to find out if there is any primary key in each table"
- Next in thread: Jacco Schalkwijk: "Re: how to find out if there is any primary key in each table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|