Posts
400
Comments
213
Trackbacks
0
Fun mit T-SQL und primary keys:

Hier ein paar Code-Snipptes die man immer mal wieder brauchen kann


Alle primary key  einer Datenbank ausgeben:

select t.name, fc.name
from sys.key_constraints as fc
inner join sys.tables as t ON fc.parent_object_id = t.object_id
where fc.type_desc='PRIMARY_KEY_CONSTRAINT'


Ausgabe des primary key der Tabellen einer Datenbank sowie deren primary key Spalte:

SELECT tc.table_name, tc.Constraint_name, ccu.column_name
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.Constraint_name
WHERE tc.CONSTRAINT_TYPE = 'Primary Key'


Alle Primary Key und Foreign Key einer Tabelle ausgeben:

SELECT Table_Name as [Table], Column_Name as [Column],
Constraint_Name as [Constraint], Table_Schema as [Schema],*
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE Table_Name = 'TabellenName'
ORDER BY [Table], [Column]

 

posted on Saturday, October 16, 2010 8:46 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 4 and 2 and type the answer here: