authentication - Create SQL Server grant user -
i created database in sql server 2014 , entered sa
, administrator.
how make sa
have permission see procedures?
and how create admin user, using code?
i tried this
create login ztestecom password = 'sqlserver';
you cannot remove 'sa' being system administrator. recommended disable sa account since known account have system administrator rights , therefore user attempted hacked.
the being said, below create user sysadmin , make yet user , grant them ability execute stored procedures in user databases. can run 'sa' account.
-- create new account secure password create login sqlmanager password = 'now master.'; go -- grant new account sysadmin rights alter server role [sysadmin] add member [sqlmanager] go -- create new role executing procedures in user db's declare @command varchar(1000) select @command = ' if ''?'' not in(''master'', ''model'', ''msdb'', ''tempdb'') begin if not exists (select 1 sys.database_principals name=''db_executor'') begin create role [db_executor]; end; grant execute db_executor; end ' exec sp_msforeachdb @command go -- create new account executing procedures create login sqlexecutor password = 'you run along now'; go -- add new user db_executor role in user db db's declare @command varchar(1000) select @command = ' if ''?'' not in(''master'', ''model'', ''msdb'', ''tempdb'') begin if not exists(select principal_id sys.database_principals name = ''sqlexecutor'') begin create user [sqlexecutor] login [sqlexecutor] default_schema=[dbo]; end; alter role [db_executor] add member [sqlexecutor]; end ' exec sp_msforeachdb @command go
finally log off sa , login sqlmanager. ensure have sysadmin permissions , disable sa account
-- disable sa account alter login [sa] disable
Comments
Post a Comment