You are on page 1of 8

SQL TASKS

1) How to map a user to an existing login sql server?


2) How to take DB offline or online?
3) How to know the collation details for particular db or all db’s?
4) How to change Authentication Modes?
5) How to change recovery model type?
6) Scripts execution?
7) How to take backup and restore?
8) User creation?
9) Maintenance plan creation for backups?

10) How to change DB from single user to multi user or multi user to single user?

11) How to shrink TEMP DB size without restarting sql server?

12) How to give granting permissions to users in sql server?

13) How to know the database backup process like how much % completed and estimation time?

14) How to identify blockings and how to resolve?

15) How to create DB (Database) role in sql server?

16) How to script out or script generation an entire DB like all the objects such as
tables, stored procedures and functions?

17) Patching?

18) How to SHRINK db and data files?

 Login to SSMS (This is mandatory step)

1) How to map a user to an existing login sql server?

GUI Method::
 Go to particular DB  security  Right click on user  new user  select user type
 Select user name  select location as entire directory  enter object name and check
connections  ok --. Give login name  select default schema like dbo.
2) How to take DB offline or online?

GUI Method::
 Right click on particular Db  Tasks  select offline or online

3) How to know the collation details for particular db or all db’s?

GUI Method::
 Right click on particular database  Go to properties  You can see only collation status in
General tab  For changing collation you should go Options tab  Select required collation 
ok.

(OR)

T.SQL

 Select particular database and click on new query and paste below script in new window and click
on execute button.

Select databasepropertex( ‘databasename’ , ‘collation’ )

4) How to change Authentication Modes?

GUI Method::
 Login to SSMS (This is mandatory step)  Right click on the instance (server) name
Go to properties  Security  Server authentication  select windows or mixed  ok.

5) How to change recovery model type?

GUI Method::

 Right click on particular database  Go to properties  Go to the options under


recovery model  select required recovery model ok.

5) Scripts execution?

 Login to SSMS  Select particular database and click on new query (one new window will open
paste that script in new window) click on execute button.
7) How to take backup and restoration?

For Backup ::

 Select particular database name  Right click on that database name  Go to Tasks  Backup 
Select ADD button and select location path  Give file name with extinction .BAK ok.

For Restoration ::

 Select particular database name  Right click on that database name  Go to Tasks  Select
restore button  select add button  select that required restoration backup file  ok.

8) User creation?

GUI Method::
 Login to SSMS  go to security  logins  click on search name  enter user name & check
name  select locations as enter directory which means Active Directory  ok
 Look at server role  select server role based on condition  click user mapping  select db
name where we want to select that particular user  select default schema as dbo  select
db role for that particular user  ok.

9) Maintenance plan creation for backups?

GUI Method::
 Launch SSMS and login  In the object explorer pane, expand the management folder 
Right click on Maintenance plans  Select Maintenance plan wizard  Click next  Specify the
name for the plan  select separate schedules for each task and then click next  On the
select maintenance tasks page select the backup database (Full or Differential or Log)  Next
 Next  Define full backup setting  Select the database that you want to backup (like all
user databases or particular databases)  Select backup media (like Disk or Tape)  select
verify backup integrity check box  In the job schedule properties select Recurring for the
schedule type  Give schedules as per requirements  ok .
10) How to change DB from single user to multi user or multi user to single user?

GUI Method:
 Right click on particular database  Go to Properties  In Restrict Access select required
mode.

(OR)

T .SQL:

 Alter database [give database name] set SINGLE_USER with rollback immediate;
 Alter database [give database name] set MULTI_USER;

11) How to shrink TEMP DB size without restarting sql server?

GUI Method:
 Expand system databases  Right click on TEMPDB  go to properties
 Just look at that size (both data and log file) and space available

Note: How to find out how much data file and log file holds the size in tempdb.

 Right click on tempdb  tasks  shrink  select file type data or log
 Select file name (:: In production mostly more than 1 file)
 Give shrink action type  ok

Note: 10 desired size in MB, Keep in mind that size needs to be more than or equal to minimum
required size of tempdb, otherwise tempdb will not shrink.

Script: For particular database Log file

Use [give db name]

DBCC SHRINKFILE (N’give dbname’ , 3 or 5 or 50 or 100............)

Go
12) How to give granting permissions to users in sql server?

 Login to SSMS  Expand security  Right click on logins  New login  Give login name in the
format of (Domain\username) in General Tab  Select authentication Mode  Select default
database as Master  Go to Server Roles  Select Public  Go to User Mapping  Select required
databases and default schema as dbo and then select database role membership  0k.

13) How to know the database backup process like how much % completed and estimation time?

When the database backup is in executing status (Not Completed) that time we should know how
much % completed and remaining estimation time like.......For this you can execute below script.

 Select particular database and select new query in that new window paste below script and click on
execute button it will give the information about backup and restore.

For Backup Information:

Select * from sys.dm_exec_requests where command like ‘%backup%’

For Restore Information:

Select * from sys.dm_exec_requests where command like ‘%restore%’

14) How to identify blockings and how to resolve?

GUI Method:
 Go to particular Db  Reports  Standard reports  All blocking transactions
 From 2008 version onwards  Go to Management  Activity Monitor  View processes
 For killing blocking  Go to Management  Activity Monitor  View processes Right
click on process ID  Kill Process.

(OR)

T.SQL

 Sp_who2 (:: It will give the information about the blockings you can find through blk column)

dbcc inputbuffer (give SPID here) :: to know which query is running


select * from sys.sysprocesses where spid>50 and blockid<>0

kill spid (:: With the proper approval )

Note: Blocking are not database level these are application level.

15) How to create DB (Database) role in sql server?

 Role is nothing but permissions like reader or writer................

In SQL server there are 2 types of role 1) Db Role

2) Application Role

For Example: There are 4 tables in DB, but we want to give permissions to see only 2 tables from out of
4 tables that time we should give db role for those 2 tables for particular users.

1) DB Role:
 Go to particular db  Security  Expand roles  Create db role (If don’t have)  Give role
name  Select owner  Go to securables  Search that object  ok  Select object type
 Go to browse button  Select matching objects  ok  Give permissions for dbo
customer.........  ok  Double click on created db role  add  Browse  Select required
users  ok.
2) Application Role:

 Here we can permissions to particular stored procedures, tables and functions etc.

16) How to script out or script generation an entire DB like all the objects such as tables, stored
procedures and functions?

::: This needs mostly in the time of Migration or Up gradation DB from one place (or server) to another
place.

 Right click on particular DB  Tasks  Scripts an generated  Next  Select DB object type
 Next  Select output type  Give the path in file name  Next  Next  Finish.

:::: If customer needs to execute this in target place or in any another server.
 Go to Target server  Click on New query  Open that saved script  Change location path
for mdf and ldf file  Execute.

17) Patching?

 2005 version: SP1, SP2, Sp3 and Sp4

2008 version: Sp1, SP2, Sp3 and Sp4

2008R2 Version: Sp1, SP2 and Sp3

2012 version: Sp1, SP2 and Sp3

2014 version: Sp1 and Sp2

2016 version: Sp1

Link: http://sqlserverversions.blogspot.in/

 Select appropriate version service pack  Go to setup file  Right click and run as
administrator  Next  Click the button I accept the licence terms  Next  Select
MSSQLSERVER or Next  Next  upgrade  Next  Finish or Close.

Note: Before going to install make conformation which service pack the server holds currently. For that
run below query.

Select @@version

18) How to SHRINK db and data files?

 Right click on particular db  tasks  Shrink  Select or give required database name  select file
type data or log or file stream  select file group select shrink action 

Note: If you want shrink log file in 2008, 2012, 2014 need to bring database into Simple recovery model
or take backup of that Transactional Log.

You might also like