Search
 
SCRIPT & CODE EXAMPLE
 

SQL

check if a column is a primary key in sql server

SELECT  K.TABLE_NAME ,
    K.COLUMN_NAME ,
    K.CONSTRAINT_NAME
FROM    INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C
        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 K.COLUMN_NAME = 'keycol';
Comment

PREVIOUS NEXT
Code Example
Sql :: How to check if the column exists in sql table 
Sql :: sort by sql 
Sql :: desc in sql 
Sql :: python sqlite data delete 
Sql :: how to delete the rows with null values in mysql 
Sql :: sql counter column 
Sql :: how to query date in sql server 
Sql :: how to find third highest salary in sql 
Sql :: SQL Multiple Cases 
Sql :: json extract 
Sql :: sql now 
Sql :: mysql user 
Sql :: sqlite3 import csv 
Sql :: postgres duplicate key value violates unique constraint already exists 
Sql :: convert multiple columns to rows in sql server 
Sql :: mysql delete entire row on condition 
Sql :: enable foreign key checks postgres 
Sql :: mysql multiple order by 
Sql :: how to set a column as unique in sql server 
Sql :: get cpu details sql 
Sql :: sql precent format 
Sql :: how to delete data from sql database in android 
Sql :: how to display value of variable in mysql 
Sql :: unique key in ms sql server 
Sql :: sqlite insert or update 
Sql :: mysql import from sql file 
Sql :: how to write lowercase in sql 
Sql :: mysql create user with grant privileges 
Sql :: download sql server for mac 
Sql :: Using GROUP BY in MySQL Join Table 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =