use DBName IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'domain\username') BEGIN IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'domain\username') CREATE USER [domain\username] FOR LOGIN [domain\username] -- db_owner是希望加给指定用户的数据库权限 exec sp_addrolemember N'db_owner', N'domain\username'; END GO
楼主如果有问题请继续追问, 没问题的话请采纳, 谢谢!