Situatie
Mai jos este o procedura ce returneaza, pe baza Microsft SQL Server pe care este rulata, toate tabelele ce nu au definita cheie primara.
Solutie
create procedure TablesWoPrimaryKey
as
SELECT
s.[name] + N’.’ + t.[name] [Table]
FROM sys.tables t
JOIN sys.schemas s ON t.[schema_id] = s.[schema_id]
WHERE NOT EXISTS
(
SELECT top 1 1
FROM sys.key_constraints kc
WHERE kc.[type] = N’PK’ AND kc.parent_object_id = t.[object_id]
);
Leave A Comment?