I also found another one for SQL Server:
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + QUOTENAME(CONSTRAINT_NAME)), 'IsPrimaryKey') = 1
AND TABLE_NAME = 'TableName' AND TABLE_SCHEMA = 'Schema'
More Related Contents:
- How can I do an UPDATE statement with JOIN in SQL Server?
- The multi-part identifier could not be bound
- Subquery using Exists 1 or Exists *
- How to insert a line break in a SQL Server VARCHAR/NVARCHAR string
- How can I query a value in SQL Server XML column
- Most efficient T-SQL way to pad a varchar on the left to a certain length?
- SQL – How to store and navigate hierarchies?
- SQL Query to get aggregated result in comma separators along with group by column in SQL Server
- Update records in table from CTE
- INT vs Unique-Identifier for ID field in database
- SQL Server date format function
- Composite Primary key vs additional “ID” column?
- Can a sql server table have two identity columns?
- Saving changes after table edit in SQL Server Management Studio
- Eliminating duplicate values based on only one column of the table
- Logging ALL Queries on a SQL Server 2008 Express Database?
- SQL query to find Nth highest salary from a salary table
- How to get export output in “real” CSV format in SQL Server Management Studio?
- Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column
- Get the records of last month in SQL server
- Log record changes in SQL server in an audit table
- Merge overlapping date intervals
- Script to save varbinary data to disk
- Access to Result sets from within Stored procedures Transact-SQL SQL Server
- alternatives to REPLACE on a text or ntext datatype
- How can I backup a remote SQL Server database to a local drive?
- How to find out what is locking my tables?
- Add a column to existing table and uniquely number them on MS SQL Server
- What is the most appropriate data type for storing an IP address in SQL server? [duplicate]
- Executing SQL query on multiple databases