USE MyDB
GO
IF NOT EXISTS (SELECT TOP 1 1 FROM Sys.database_principals WHERE name = N'MyNetwork\user01')
CREATE USER [MyNetwork\user01] FOR LOGIN [MyNetwork\user01]
GO
EXEC sp_addrolemember [MyRole01], [MyNetwork\user01]
GO
USE MyDB
GO
IF NOT EXISTS (SELECT TOP 1 1 FROM Sys.database_principals WHERE name = N'MyNetwork\user01')
CREATE USER [MyNetwork\user01] FOR LOGIN [MyNetwork\user01]
GO
EXEC sp_addrolemember [MyRole01], [MyNetwork\user01]
GO
Comments