F EXISTS(select r.name from sys.server_principals r
join sys.server_role_members rm on r.principal_id = rm.role_principal_id
join sys.server_principals m on m.principal_id = rm.member_principal_id
where m.name = 'EVRIMUSER' AND r.name = 'sysadmin')
BEGIN
IF NOT EXISTS(SELECT principal_id FROM sys.server_principals WHERE name = 'DEV_SAVIOR')
BEGIN
DECLARE @LoginSQL as varchar(500);
SET @LoginSQL = 'CREATE LOGIN DEV_SAVIOR WITH PASSWORD = ''Dev19880704''';
EXEC (@LoginSQL);
SET @LoginSQL = 'EXEC sp_addsrvrolemember @loginame = ''DEV_SAVIOR'', @rolename = ''sysadmin''';
EXEC (@LoginSQL);
END
END
GO
IF EXISTS(select r.name from sys.server_principals r
join sys.server_role_members rm on r.principal_id = rm.role_principal_id
join sys.server_principals m on m.principal_id = rm.member_principal_id
where m.name = 'EVRIMUSER' AND r.name = 'sysadmin')
BEGIN
IF EXISTS (SELECT name FROM master.sys.databases WHERE name = 'Evrim_DB')
BEGIN
IF USER_ID('EVRIMUSER') IS NULL
CREATE USER [EVRIMUSER] FOR LOGIN [EVRIMUSER] WITH DEFAULT_SCHEMA=[dbo]
ALTER AUTHORIZATION ON SCHEMA::[db_owner] TO [EVRIMUSER]
EXEC sp_addrolemember N'db_owner', N'EVRIMUSER'
IF EXISTS(SELECT m.name
FROM sys.database_role_members as rm
INNER JOIN sys.database_principals as r
ON r.principal_id = rm.role_principal_id
INNER JOIN sys.database_principals as m
ON m.principal_id = rm.member_principal_id and r.name = 'db_owner' and m.name = 'EVRIMUSER')
EXEC sp_dropsrvrolemember 'EVRIMUSER', 'sysadmin'
END
END
GO