我有一张带 PK 的桌子
create table a(x int constraint PK_x primary key(x))
如何制作防止 PK 丢失的 DDL 触发器?
alter table a drop constraint PK_x
如果约束是来自 EVENTDATA 的 PK,我无法获得
<EVENT_INSTANCE>
<EventType>ALTER_TABLE</EventType>
<PostTime>2021-11-04T13:08:11.417</PostTime>
<SPID>73</SPID>
<ServerName>SQL2017</ServerName>
<LoginName>sa</LoginName>
<UserName>dbo</UserName>
<DatabaseName>(redacted)</DatabaseName>
<SchemaName>dbo</SchemaName>
<ObjectName>a</ObjectName>
<ObjectType>TABLE</ObjectType>
<AlterTableActionList>
<Drop>
<Constraints>
<Name>PK_x</Name>
</Constraints>
</Drop>
</AlterTableActionList>
<TSQLCommand>
<SetOptions ANSI_NULLS="ON" ANSI_NULL_DEFAULT="ON" ANSI_PADDING="ON" QUOTED_IDENTIFIER="ON" ENCRYPTED="FALSE" />
<CommandText>alter table a drop constraint PK_x</CommandText>
</TSQLCommand>
</EVENT_INSTANCE>