Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
TSQL 15
BRH 13
SQL Server 13
#SQL Server 12
#TSQL 8
#SQLServer 4
SQL Server Agent 3
Stored Procedure 2
SQL server Jobs 2
Change Data Capture CDC 2

Archive · View All
November 2010 4
October 2010 3
April 2011 3
March 2011 3
January 2012 2
November 2011 2
August 2011 2
September 2010 1
October 2011 1

TSQL to get All Primary Key Columns and its relevant details

Oct 4 2011 4:09AM by Manjunath C Bhat   

I was working on database design stuff and came across a situation where in i had to get all the primary keys existing in database for all tables and the primary key columns and column details. It would be very had and insane to go into each table and search for PK and its data. So i came up with this small script which gives you all information on Primary Keys. This can be modified as per your needs to get more information or for foreign keys ets. Hope this is useful for some guys looking for it. It was very helpful for me though :)

SELECT SS.NAME AS [TABLE_SCHEMA], ST.NAME AS [TABLE_NAME]
     , SKC.NAME AS [CONSTRAINT_NAME], SC.NAME AS [CONSTRAINT_COLUMN_NAME],
     CAST(STY.NAME AS VARCHAR(20)) +'('+
     CAST(CASE ST.NAME
     WHEN 'NVARCHAR' THEN (SELECT SC.MAX_LENGTH/2)
     ELSE (SELECT SC.MAX_LENGTH)
     END AS VARCHAR(20)) +')' AS [DATA_TYPE]
  FROM SYS.KEY_CONSTRAINTS AS SKC
  INNER JOIN SYS.TABLES AS ST
    ON ST.OBJECT_ID = SKC.PARENT_OBJECT_ID
  INNER JOIN SYS.SCHEMAS AS SS
    ON SS.SCHEMA_ID = ST.SCHEMA_ID
  INNER JOIN SYS.INDEX_COLUMNS AS SIC
    ON SIC.OBJECT_ID = ST.OBJECT_ID
   AND SIC.INDEX_ID = SKC.UNIQUE_INDEX_ID
  INNER JOIN SYS.COLUMNS AS SC
    ON SC.OBJECT_ID = ST.OBJECT_ID
   AND SC.COLUMN_ID = SIC.COLUMN_ID
  INNER JOIN SYS.TYPES AS STY
      ON SC.USER_TYPE_ID = STY.USER_TYPE_ID
  ORDER BY TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME;

Happy Coding.

Thanks and Regards,

Manjunath C Bhat 

Tags: brh2, #SQLServer, TC_Challenge, TSQL Challenge, challenge 66, TCchallenge66, TC_Challenge 66, challenge66, TSQL Challenge 66,


Manjunath C Bhat
102 · 2% · 511
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"TSQL to get All Primary Key Columns and its relevant details" rated 5 out of 5 by 1 readers
TSQL to get All Primary Key Columns and its relevant details , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]