DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to test column for PRIMARY KEY constraint?

Execute the following Microsoft SQL Server T-SQL script in Management Studio Query Editor to demonstrate how to check if a column is PRIMARY KEY.

 

USE AdventureWorks2012;

GO

 

IF EXISTS (SELECT 1

FROM   INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C

       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K

         ON C.TABLE_NAME = K.TABLE_NAME

            AND C.CONSTRAINT_CATALOG = K.CONSTRAINT_CATALOG

            AND C.CONSTRAINT_SCHEMA = K.CONSTRAINT_SCHEMA

            AND C.CONSTRAINT_NAME = K.CONSTRAINT_NAME

WHERE  C.CONSTRAINT_TYPE = 'PRIMARY KEY'

       AND COLUMN_NAME = 'SalesOrderID'

       AND C.TABLE_NAME = 'SalesOrderHeader'

       AND C.TABLE_SCHEMA = 'Sales')

PRINT 'PRIMARY KEY'; 

/* Messages

PRIMARY KEY

*/

------------

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE