Tuesday, March 8, 2016

Administrative commands

--logins permissions
--authentication, authorization
--Create a sql Server login
Create login Alberts with password='Pass'

Use CommunityAssist
--add a user in communityAssist mapped to that login 
Create user Alberts for Login Alberts

--create a new role
Create Role EmployeeRole

--Grant permissions on objects to the role
Grant Select on CommunityService to EmployeeRole
Grant Select, Update on Person to EmployeeRole
Grant Select, Update, Insert on ServiceGrant to EmployeeRole
Grant Select on BusinessRules to EmployeeRole

--add the user to the role
exec sp_addrolemember 'EmployeeRole', 'Alberts'

--does exactly the same as the above
Alter role EmployeeRole Add member Alberts

Select * from sys.syslogins

use CommunityAssist
Select * from Person

--schema. A schema is a collection of related objects
go
--create a scheam
Create schema ClientSchema
Go
--add a view to the schema. Note the SchemaName.ObjectName
Create view ClientSchema.vw_Grants
As
Select GrantDate, GrantAmount, PersonKey,
GrantNeedExplanation
From ServiceGrant
go
Create view ClientSchema.Vw_Services
As
Select ServiceName, ServiceDescription, ServiceMaximum, ServiceLifetimeMaximum
From CommunityService
go
--create another role
Create role NewClientRole

--add permisions on the schema to the role
Grant Select on Schema::ClientSchema to NewClientRole

--new login
Create login Larry with password='Pass'
--new user with a default schema
Create user LarryUser for Login Larry with default_schema=ClientSchema
go
--Add user to role
Alter role NewClientRole Add member LarryUser

/*****************
backups and restores
*******************/
--a full backup
Backup Database CommunityAssist to disk ='C:\Backups\CommunityAssist.bak'
--a differential backup
Backup Database CommunityAssist to disk ='C:\Backups\CommunityAssist2.bak'
with Differential
--restore. Must restore the full then the differentials, then the log if backed up
use Master
Restore Database CommunityAssist from disk='C:\Backups\CommunityAssist.bak'
with norecovery
Restore Database CommunityAssist from Disk='C:\Backups\CommunityAssist2.bak'
with recovery

No comments:

Post a Comment