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 VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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
SQL 2016 DESIGN & PROGRAMMING
 
 
 
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