SQL Notes Day2
SQL Notes Day2
SQL Notes Day2
NTFS default memory block size is 8kb. Same for MSSQL. Extent=64kb with 8 pages. An extent can have more than one table pages (Data).--- Mixed Extent Uniform Extent, Mixed Extent. Global Allocation mapping.(GAM)
http://venkattechnicalblog.blogspot.com/ shared global Allocation map(SGF) differential changed map Bulk changed mapping codeplex.com----- internals viewer tool to view fragmentation
sp_configure 'show advanced options',1 reconfigure sp_configure 'show advanced optionsrecovery interval (min)', 100000 reconfigure creating indexes on the where clause condition column make good speed. Since all the rows in the same pafe increase I/o speed. LOGFILE- sequential R/w --- Log Sequence Num(LSN)---WAL technique(Write ahead Log)- for DML statement only(update,write...) y y y y y y y Comitted trans cannot be rolled Back. Clearing Buffer after written into the Harddisk from Ram whwn Log file contains comit info. Automatic Check Point when comit happed Lazy writter- if RAM is filled automaticaly comit and relase the RAM With out Begin Tran of query it is a autocomit transation but it will rollback automaticaly when again after Ram free or power of happened using Log file. (acid properties of sql server) Select statement(Non DML statement) Dont use WAL it uses Lazy writer Least Recently Used(LRU) Page Technique using aging Factor, () Aging factor of Page in RAM= I/o cost* Reference counter y Data file-Randam R/w Forward Pointer is used in LSN to check commit log in speed
Data file backup, alter table, Restart of server are firing the check point. But Logfile Back up doesnot fire check point. Do fire check point frequently since it will clear RAM by deleting unnnesecary data or comitted data. Virtual Log File usin min LSN pointer used to back up the part of the log file after that prat VLF is commited(finished transaction) ---- circular log backup VLogfile1 Vlogfile2 Vlogfile3 Vlogfile4
Vlogfile5
Sp_settriggerorder for give priority to tigger Constraints are proactive but triggers are reactive Trun is used to delete seed(primary) value also but delete donot delete seed values RAID(Redundant Array independent disk) RAID 1,0 and RAID 1,5 is more used in SQL
--to read ldf file dbcc log(test1,2) log(testdb,-1) ----1 most detail info of log file
checkpoint after execution of checkpoint less log info becuse that log info is backed up.
sp_configure 'show advanced options',1 reconfigure sp_configure 'show advanced optionsrecovery interval (min)', 100000 reconfigure select * from t1 begin tran insert into t1 values(290,280) update t1 set c2=100 where c1=30 commit tran rollback tran sp_helpfile --to read ldf file dbcc log(test1,1) --checkpoint
-- table partition alter database test1 add filegroup FG13 -- add file alter database test1 add file (name=cash1,filename='C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Cash_data.mdf', size=5mb, maxsize=10mb, filegrowth=20%) to filegroup FG1 -- partition function creation create partition function FN1(int) as range left for values(10,100,1000) ---scheme create partition scheme sch2 as partition FN1 to (FG1,FG10,FG11,FG13) create table testtable1 ( n1 int, n2 char(5) ) on sch2(n1) --- Crete Test2 db create database Test2 alter database test2 add filegroup FG3 -- add file alter database test1 add file (name=cash2,filename='C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Cash2_data.mdf', size=5mb, maxsize=10mb, filegrowth=20%) to filegroup FG1 -- partition function creation create partition function FN1(int) as range left for values(10,100,1000) ---scheme create partition scheme sch1 as partition FN1 to (FG1,FG10,FG11,FG13) create table testtable ( n1 int, n2 char(5) ) on sch1(n1)
Sliding Window Tech: sp_addumpdevice 'disk',advbackup, 'c:\advbackup.bak' select * from sys.sysdevices backup database test1 to advbackup
o --back up database sp_addumpdevice 'disk',advbackup, 'c:\advbackup.bak' select * from sys.sysdevices o backup database test1 to advbackup -- Restore data base after droping Drop database test1 Restore filelistonly from advbackup
-- Restore full DATA to a empty DB Restore database test1 from advbackup with move 'test_data' to 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Test1_data.mdf', move 'test_log'to 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Test1_log.ldf'