Situatie
Pentru a vedea ce tabele dintr-o baza nu au PK am facut o procedura care returneaza tabelele fara Primary Key de pe baza pe care este rulata
Solutie
create procedure BD_TabeleFaraPK_prc
as
SELECT s.[name] + N’.’ + t.[name] as Tabela
FROM sys.tables t
INNER JOIN sys.schemas s ON t.[schema_id] = s.[schema_id]
WHERE NOT EXISTS
(
SELECT * FROM sys.key_constraints kc
WHERE kc.[type] = N’PK’ AND kc.parent_object_id = t.[object_id]
)
Leave A Comment?