Tabele fara Primary Key

Configurare noua (How To)

Situatie

Pentru cazurile in care ne cere audit-ul sau chiar pentru cazurile in care avem nevoie noi de asa ceva pentru o mai buna administrare a serverului de sql, am facut o procedura ce returneaza toate tabelele ce nu au definite PK pe acestea.

Solutie

create procedure BD_FindAllTablesWithoutPK_prc

as

select name
from sysobjects
where type=’U’
and name not in(
select distinct table_name
from information_schema.key_column_usage
where constraint_catalog = db_name()
and lower(constraint_name) like ‘pk%’
and table_name not like ‘tbl_core_%’
and table_name not like ‘db_version_1%’
and table_name not like ‘dtproperties’
and LOWER(constraint_name) like ‘pk%’)

order by name

Tip solutie

Permanent

Voteaza

(27 din 51 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?