Академический Документы
Профессиональный Документы
Культура Документы
| (vertical bar) = Separates syntax items within brackets or braces. You can choose only one of the items.
[ ](brackets)= Optional syntax items. Do not type the brackets.
{ }(braces)= Required syntax items. Do not type the braces.
[,...n]= Indicates the preceding item can be repeated n number of times.The occurrences are
separated by commas.
[...n] = Indicates the preceding item can be repeated n number of times.The occurrences are
separated by blanks.
[;]= Optional Transact-SQL statement terminator.Do not type the brackets.
<label> ::= The name for a block of syntax. This convention is used to group and label sections of
lengthy syntax or a unit of syntax that can be used in more than one location within a
statement.Each location in which the block of syntax can be used is indicated with the
label enclosed in chevrons: <label>.
--It displays the what are the logins available in SQL SERVER
--Syslogins is the table available in Master database
CMD> select * from syslogins
--It display the current user
CMD> select user_name()
--It shows the user information
CMD> sp_helpuser
CMD> sp_helpuser manoharreddy
--Through this we can identify how many server roles available in sql server with description
CMD> sp_helpsrvrole
--we can identify the specified server role description
CMD> sp_helpsrvrole 'sysadmin'
--How many members add this sysadmin role
CMD> sp_helpsrvrolemember 'sysadmin'
CMD> sp_helpsrvrolemember 'dbcreator'
--What he can do
CMD> sp_srvrolepermission
CMD> sp_srvrolepermission 'sysadmin'
CMD> sp_srvrolepermission 'dbcreator'
--We can identify what rights have been granted in a database
--Here mano is the database
CMD> use mano
CMD> sp_helprotect
--GRANT,DENY,REVOKE permissions ON DATABASE /OBJECTS---GRANT:: gives a user permission to perform certain tasks on Database objects
--DENY :: denies any access to a user to perform certain tasks on database objects
--REVOKE: removes a grant or deny permission from a user on certain database objects
CMD> create database mano
--We can identify what rights have been granted in a database
CMD> use mano
CMD> sp_helprotect
--We can also grant users permissions to do other tasks such as create tables,views,stored
procedures,....
CMD> grant create table to manoharreddy
--Grants permissions on a database.
--Syntax is
GRANT <permission> [ ,...n ]
TO <database_principal> [ ,...n ] [ WITH GRANT OPTION ]
[ AS <database_principal> ]
<permission>::=
permission | ALL [ PRIVILEGES ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
--through this we can grant the permission on database level
CMD> grant insert to manoharreddy
--Grants permissions on a database user, database role, or application role.
--Syntax is
GRANT permission [ ,...n ]
ON
{ [ USER :: database_user ]
| [ ROLE :: database_role ]
| [ APPLICATION ROLE :: application_role ]
}
TO <database_principal> [ ,...n ]
[ WITH GRANT OPTION ]
[ AS <database_principal> ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
--Grants permissions on a table, view, table-valued function, stored procedure,extended stored
procedure, scalar function, aggregate function, service queue, or synonym
--Syntax is
GRANT <permission> [ ,...n ]
ON
[ OBJECT :: ][ schema_name ]. object_name
[ ( column [ ,...n ] ) ]
TO <database_principal> [ ,...n ]
[ WITH GRANT OPTION ]
[ AS <database_principal> ]
<permission> ::=
ALL[ PRIVILEGES] | permission[( column [ ,...n ] ) ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
--Enter into the specified database then give the permissions
--allow users mano,manoharreddy to select,insert & update data on table emp
CMD> Use mano
CMD> grant insert,update,select on emp to manoharreddy,mano
--Denies permissions on a database.
--Syntax is
DENY <permission> [ ,...n ]
TO <database_principal> [ ,...n ] [ CASCADE ]
[ AS <database_principal> ]
<permission> ::=
permission | ALL [ PRIVILEGES ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
--Deny delete access to table hostel for user mano,manoharreddy
CMD> Use mano
CMD> deny update on emp to mano,manoharreddy
--Revokes permissions granted and denied on a database
--Syntax is
REVOKE [ GRANT OPTION FOR ] <permission> [ ,...n ]
{ TO | FROM } <database_principal> [ ,...n ]
[ CASCADE ]
[ AS <database_principal> ]
<permission> ::=
permission | ALL [ PRIVILEGES ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
--Remove update access to table emp for user mano
Full
bulk logged
simple
Full:
Simple:
Bull logged:
backup:
backup is nothing but copy of orginal data.
types of backup:
full
diff
tlog file or filgroup
mirror
split
copy_only
taillog
compression backups
suspect
restoring..
stanby
offline
fullbackup:
dbcc showfilestats
size of database
revoery model
transaction rate
availiability(24/7)
Q2:my datbase size 600 GB and daily 30000 trnaction suggetble stragegy.
changes made after fullback up can be taken into file with diff backup
it is generated fast as compared with full backup
it captures all extents that have changed since the last full backup
it reduces time of recovery in case of database failure no need restore all log backup made after full backup
diff:
how it works:
changes made after full backup are wirtten into dcm pages which base to take diff backups.
when changed are made to extends in the database sql server set the bit corresponding to the extent to 1
when diff backup is generated first sql server goes to dcm pages to find changed extends information and write these changes into diff backup
case :
Every Sunday i have configured full backup and Diff backups
backup generated on Friday has all transaction from since last Sunday
D ---full
I - diff/incremental
F file
L --t.log
FG -- filegroup
tlog:
tail-log:
it is last transaction log backup which should be taken before restoring database in the event of database failure
can't truncate the t.log
t.log:
taillog backup:
Q1:every sunday 5am full backup everyday 5am diff and every 15 mints tlog backup, database was failed 5.30 am on Friday then how to
recovery db..
no disk space
server was busy
msdb was offline
agent services are stopped mode
net work problem
transaction log file is full
Split:
if the size of backup is large where there is no required disk space in any drive we can split backup in to multiple files
backup db dbname to disk = '',
dsik = '',
disk = '' with noformat ,stats = 10
-------------------BACKUP THE DATABASES --------------------------------------------FULL:
FILE&FILEGROUP
BACKUP DATABASE tecno FILEGROUP = 'PRIMARY' TO DISK = 'C:\Primary\full.bak'
Tail-log
backup log tecno to disk = 'D:\BACKUP\tlog.trn' with no_truncate(note date&time when willu take backup)
============How can I monitor that all Databases are backing up as per plan =======
SELECT
CONVERT(CHAR(100), 'JPRWINDRESTO') AS Server,
bs.database_name,bs.backup_start_date,bs.backup_finish_date,bs.expiration_date,CASE bs.type
WHEN 'D' THEN 'Full Database'
WHEN 'L' THEN 'Log'
WHEN 'I' THEN 'Differential'
WHEN 'F' THEN 'File Level'
WHEN 'G' THEN 'File Level Differential'
WHEN 'P' THEN 'Partial'
WHEN 'Q' THEN 'Differential partial'
END AS backup_type,
convert(varchar,cast(bs.backup_size/1024/1024 as money),10) as 'Backup
Size in MB',
bmf.logical_device_name,
bmf.physical_device_name,
bs.name AS backupset_name,
bs.description
FROM msdb.dbo.backupmediafamily bmf
INNER JOIN msdb.dbo.backupset bs ON bmf.media_set_id = bs.media_set_id
WHERE (CONVERT(datetime, bs.backup_start_date, 102) >= GETDATE() - 10)
ORDER BY
bs.database_name,
bs.backup_finish_date
=====monitor What all Databases are not being backup in last 24 hours========
SELECT
CONVERT(CHAR(100), 'JPRWINDRESTO') AS Server,
bs.database_name,
MAX(bs.backup_finish_date) AS last_db_backup_date,
DATEDIFF(hh, MAX(bs.backup_finish_date), GETDATE()) AS [Backup Age (Hours)]
FROM msdb.dbo.backupset bs
WHERE bs.type = 'D'
GROUP BY bs.database_name
HAVING (MAX(bs.backup_finish_date) < DATEADD(hh, - 48, GETDATE()))
USE msdb;
SELECT physical_name FROM sys.database_files
GO
-- Find last FUll backup datetime and path?-select top 1 bs.backup_finish_date, bs.database_name, bs.server_name, bmf.physical_device_name
from msdb.dbo.backupset bs
inner join msdb.dbo.backupmediafamily bmf on bs.media_set_id = bmf.media_set_id
where bs.database_name = 'HRTFS' and bs.type = 'D' --'L' for log backups ,I diff
Backing up the transaction log file on the primary SQL Server instance
Copying the transaction log backup file across the network to one or more secondary SQL Server instances
Restoring the transaction log backup file on the secondary SQL Server instances
Implementation examples
One of the common log shipping scenarios is the environment with two servers (SQLServer-1 primary and SQLServer-2 secondary), two
SQL Server instances (SQLInstance-1 and SQLInstance-2), and one SQL Server database named SQLDB-1 with log shipping running on it
Another common configuration is the environment with three (or more) servers (SQLServer-1 primary, SQLServer-2 secondary, and
SQLServer-3 secondary), three SQL Server instances (SQLInstance-1, SQLInstance-2, and SQLInstance-3), and one SQL Server database
named SQLDB-1 with log shipping running on it
Operating modes
There are two available modes and they are related to the state in which the secondary, log shipped, SQL Server database will be:
Standby mode the database is available for querying and users can access it, but in read-only mode
The database is not available only while the restore process is running
The restore job can be delayed until all users disconnect themselves
The database log shipping setup needs to be initiated from the principal server using the SQL Server Management Studio wizard. The first step
defines transaction log backup settings:
Schedule type
Frequency
Duration
The next step defines secondary databases which involve choosing the secondary SQL Server instance and secondary database. The full database
backup, from the primary database, must be restored on the secondary server before log shipping commences
After initializing the secondary database you must define the copy folder where the transaction log backups from the primary server will be
stored
The final step involves choosing from two available modes: The No recovery Restore mode and Standby mode. You can also delay the
restoring process and set up an alert if no restore occurs within the specified time
Once the log shipping is ready for use, it will run in the background, and if the problem occurs the alert will signalize the problem