USE [master] GO CREATE LOGIN [Roy] WITH PASSWORD=N'1', DEFAULT_DATABASE=[Test], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF GO USE [Test] GO CREATE USER [Roy] FOR LOGIN [Roy] GO USE [Test] GO /****** 物件: Schema [Roy] 指令码日期: 08/19/2011 09:46:15 ******/ CREATE SCHEMA [Roy] AUTHORIZATION [Roy] go use [Test] GO GRANT CREATE TABLE TO [Roy] GO
CREATE TRIGGER tr_DBDropTable ON DATABASE FOR DROP_TABLE,ALTER_TABLE AS IF ORIGINAL_LOGIN()='Roy' BEGIN PRINT '没权限执行 DROP TABLE' ROLLBACK end
GO
--以下测试,用登陆用户Roy
go CREATE TABLE Roy.Roy(ID int) GO SELECT SUSER_NAME(), USER_NAME();
DROP TABLE Roy.Roy /* 没权限执行 DROP TABLE 讯息 3609,层级 16,状态 2,行 2 交易在触发程序中结束。已中止批次。 */
じ★ve妳
2024-10-23 10:14:20
这是我测试 胡写的 ALTER DATABASE studydb SET RECURSIVE_TRIGGERS on GO IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID=OBJECT_ID('tb') AND [type]='u') begin DROP TABLE tb END go CREATE TABLE tb ( testfield VARCHAjR(50) )