Search This Blog
Thursday, January 10, 2013
SQL Server Performance Killers
Thursday, April 26, 2012
Recovering SQL Server Database From Suspect Mode
- ALTER DATABASE [database_name]
SET EMERGENCY - DBCC checkdb('database_name')
- ALTER DATABASE
[database_name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE - DBCC CheckDB ('database_name', REPAIR_ALLOW_DATA_LOSS)
- ALTER DATABASE [database_name]
SET MULTI_USER
If it does not work for you, then go for thrid party tool or restore database from available backups.
Sunday, August 7, 2011
Playing with NULL
Wednesday, December 15, 2010
Microsoft® SQL Server® code-named 'Denali' - Community Technology Preview 1 (CTP1)
Overview
With SQL Server code-named 'Denali' customers will benefit from the following added investments:
- Enhanced mission-critical platform: A highly available and scalable platform designed to with greater flexibility, lower TCO, ease of use, and the performance required by the most mission-critical applications.
- Developer and IT Productivity: New additional tools will help developers build innovative applications with reduced time-to-market while IT professionals benefit from greater operational control and ease of use.
- Pervasive Insight: Stunning new managed self-service experiences for end users and holistic data integration and management tools will help deliver consistent, credible data to the right users at the right time.
Tuesday, December 14, 2010
Monitoring Transactional Replication Status - SQL Server 2005, 2008, 2008 R2
Monday, November 1, 2010
DDL EVENTS List - SQL Server 2008/R2
You can create trigger to fire on all events defined under a group, then you can create trigger for that particular group like "DDL_TABLE_EVENTS", this trigger will fire on all three sub-events defined under this group; these are CREATE_TABLE, ALTER_TABLE and DROP_TABLE. Similarly if you want to have a trigger to fire only for a particular event in an event group, then specify only that particular event like "ALTER_TABLE".
See example below as well:
.gif)
Friday, October 29, 2010
Script: view information of currently running SQL Server Jobs
- Job_Name: This is job’s registered name on the server’s instance.
- Last_Executed_Step_ID: This is the ID of the last executed step in the job. E.g. if a job has 4 steps, and currently it is running 3rd step, so last executed step will be 2 and it will be populated with 2 against Job’s 2nd step row, while all other steps rows will have 0.
- Step_ID: This query returns all steps included in the job along with their id, while 2nd column, returns id same as in this column.
- Step_Name: This reflects job step name that was given during job creation.
- Start_Execution_Date: This column returns execution date and time of this job. So you can get an idea when this started execution.
LTRIM(RTRIM(CONVERT(VARCHAR(100),j.name))) job_name
FROM msdb.dbo.sysjobs j WITH (NOLOCK)
WHERE j.enabled=1
ORDER BY 1,3
Monday, October 25, 2010
Compound Operators - SQL SERVER 2008/R2
- += (Add EQUALS), you can use it for string concatenation as well.
- -= (Minus EQUALS)
- *= (Multiply EQUALS)
- /= (Divide EQUALS)
- %= (Modulo EQUALS)
- &= (Bitwise AND EQUALS)
- |= (Bitwise OR EQUALS)
- ^= (Bitwise Exclusive OR EQUALS)
Wednesday, October 20, 2010
Enhanced VALUES Clause (ROW Constructor) – SQL SERVER 2008 / R2
Friday, October 15, 2010
SQL Server 2008 SP2 Release (download link)
15K partitioning Improvement. Introduced support for a maximum of 15,000 partitions in tables and indexes in Microsoft SQL Server 2008 Service Pack 2 in the Enterprise, Developer and Evaluation Editions.
Reporting Services in SharePoint Integrated Mode. SQL Server 2008 SP2 provides updates for Reporting Services integration with SharePoint products. SQL Server 2008 SP2 report servers can integrate with SharePoint 2010 products. SQL Server 2008 SP2 also provides a new add-in to support the integration of SQL Server 2008 R2 report servers with SharePoint 2007 products.
SQL Server 2008 R2 Application and Multi-Server Management Compatibility with SQL Server 2008.
SQL Server 2008 Instance Management.With SP2 applied, an instance of the SQL Server 2008 Database Engine can be enrolled with a SQL Server 2008 R2 Utility Control Point as a managed instance of SQL Server.
Data-tier Application (DAC) Support.Instances of the SQL Server 2008 Database Engine support all DAC operations delivered in SQL Server 2008 R2 after SP2 has been applied. You can deploy, upgrade, register, extract, and delete DACs. SP2 does not upgrade the SQL Server 2008 client tools to support DACs. You must use the SQL Server 2008 R2 client tools, such as SQL Server Management Studio, to perform DAC operations. A data-tier application is an entity that contains all of the database objects and instance objects used by an application. A DAC provides a single unit for authoring, deploying, and managing the data-tier objects.
Monday, October 11, 2010
Moving User Database Files in SQL Server 2000
0. Take Full backup before moving files
1. Set database in single user mode
use master
go
exec sp_dboption testdb2000,'single user','true'
go
2. Get path of database files
Exec sp_helpdb testdb2000
go
3. Save location of all files
C:\Program Files\Microsoft SQL Server\MSSQL$INS2000\data\TestDB2000_Data.MDF
C:\Program Files\Microsoft SQL Server\MSSQL$INS2000\data\TestDB2000_Log.LDF
4. De-attach this database
Exec sp_detach_db @dbname = 'testdb2000','true'
go
5. Copy all files available in step 2 and paste them to a new location
6. Rename them on their old location, just in case of any issue to revert back changes
7. After copying them to a new location, attach these files from new location to this database, you can attach upto 16 files through this procedure.
Exec sp_attach_db @dbname = 'testdb2000', @filename1 = 'd:\testdb2000\TestDB2000_Data.MDF', @filename2 = 'd:\testdb2000\TestDB2000_Log.LDF'
go
8. Connect to user database and verify changes, after verification, remove old file from old location
Saturday, April 25, 2009
Utility to see Logins and users on an instance
http://cid-2512e6af14d229c4.skydrive.live.com/self.aspx/SQL%20Server%20Utilities/Instance%20Users%20and%20Logins%20Details.zip
Description:
You can see available logins on an instance and users list in a databases, their fixed roles at server and database level, categorized as server login and database user, Object level permission details.
Pre-requistes:
.Net Framwork 2.0 installed
Only for SQL Server 2005+
Wednesday, April 15, 2009
List of Running Sessions and their Requests on an Instance
http://cid-2512e6af14d229c4.skydrive.live.com/self.aspx/SQL%20Server%20Utilities/Running%20Requests%20on%20an%20Instance.zip
Pre-requists:
.Net Framwork 2.0 or +
Only for SQL Server 2005+
Developed using VB .Net
Description:
This is an executable file that is available in zip formate at above link.
You can view all logins sessions and their running requests on an instance by providing SQL Server instance name or IP Address and can filter them by database by getting all db name or providing db name by writing in combo box.
Wednesday, February 18, 2009
Moving database files
We have three kinds of database files: log files (*.ldf), primary data files (*.mdf) and secondary data files (*.ndf).
Primary data file is the starting point for a database and points to all other files in it. Each database has one primary data file. There can be 0 or >0 secondary data files in a database to make up data files other than primary data file. Log files hold all log information that is used to recover database. There must be at least one log file for a database but it can be more than one.
If you initially create a database by using default locations or defining new one at run time. After sometime if you want to move database files to a new location by considering capacity of current disk or for any other system maintenance.
How you will move them?
Let’s see below!
We have two considerations to move database files from one location to another.
a) Planned relocation procedure
b) Relocation for scheduled disk maintenance
Although you can follow both procedures alternatively, but it depends on the environment and scenario in which you are working. If your concern with only db files move then “Planned relocation procedure” is most suitable in every scenario, because it affects the processes only for relevant database, till the time it comes online.
Planned relocation procedure:
You can follow this procedure when you require less downtime for production, or to minimize relocation impact on other process like replication, log shipping etc, mostly when you want to move files permanently to another location without affecting other databases.
Steps are:
1) Run ALTER DATABASE [database name] SET OFFLINE.
2) Move file to new location
3) Run ALTER DATABASE [database name] MODIFY FILE ( NAME = [logical name], FILENAME = 'path and filename'.
4) Run ALTER DATABASE [database name] SET ONLINE.
Relocation for scheduled disk maintenance:
You can follow this procedure, when you need to move database files to another location to perform any server or disk maintenance activity, like disk de-fragment and you can bear downtime for all databases available on that particular server.
Steps are:
1) Run ALTER DATABASE [database name] MODIFY FILE ( NAME = [logical name], FILENAME = 'path and filename'.
2) Sql server is stopped or system is shutdown to perform maintenance.
3) Move file to new location.
4) Restart server.
Tuesday, February 10, 2009
Preliminary checks for MS DTC
- You are able to ping both server from each other. If not then define them in their host files and try to ping them again, till it resolves.
- All MS DTC configurations should be same on both servers.
a) NETWORK DTC Access
b) Client and Administration (Allow remote clients, Allow remote administration)
c) Transaction Communication Manager (Allow Inbound, Allow outbound, Mutual authentication required, Incoming caller authentication required, No authentication required, Enable TIP Transactions)
d) Enable XA Transaction
e) DTC Logon Account [Should be NT Authoriy/Networkservice]
Permissions: You must have administrator access to play with above configurations.
How to access MS DTC?
Control Panel > Administrative Tools > Component Services > Component Services > Computers > My Computer > right click on it and then click on Properties and then click on MS DTC tab.
How to access Host file?
"C:\Windows\System32\Drive\etc\", you will find a file with the name of "Host"
Wednesday, January 14, 2009
Database & Disk space analysis
BEGIN
CREATE TABLE #LOGSPACE
(DBNAME VARCHAR(100)
,LOGSIZE DECIMAL(30,10)
,LOGSPACE DECIMAL(30,10)
,STATUS INT
)
CREATE TABLE #DRIVESPACE
(DRIVE VARCHAR(2)
,DRIVESPACE BIGINT
)
INSERT INTO #LOGSPACE
EXEC ('DBCC SQLPERF(LOGSPACE)')
INSERT INTO #DRIVESPACE
EXEC ('MASTER.SYS.XP_FIXEDDRIVES')
SELECT F.TYPE_DESC DBFILES
,LEFT(F.PHYSICAL_NAME,1) DRIVE
,F.STATE_DESC DBSTATE
,((F.[SIZE]*8)/1024.00)/1024.00 DBCURRENTSIZE
,ISNULL(((A.RESERVED*8)/1024.00)/1024.00 - ((D.LOGSIZE/1024.00) * (D.LOGSPACE/100.00)),(L.LOGSIZE/1024.00) * (L.LOGSPACE/100.00)) DBRESERVEDSIZE
,CASE WHEN F.IS_PERCENT_GROWTH=0 THEN 'PAGES' WHEN F.IS_PERCENT_GROWTH=1 THEN 'PERCENTAGE' END DBGROWTHTYPE
,F.GROWTH DBGROWTHVALUE
,CASE WHEN F.IS_PERCENT_GROWTH=0 THEN ((F.GROWTH*8)/1024.00)/1024.00 WHEN F.IS_PERCENT_GROWTH=1 THEN (((F.[SIZE]*8)/1024.00)*(F.GROWTH/100.00))/1024.00 END DBGROWTHSIZE
,CASE WHEN F.MAX_SIZE=0 THEN 'FIXED SIZE' WHEN F.MAX_SIZE=-1 THEN 'UNLIMITED' ELSE CONVERT(VARCHAR,((CONVERT(BIGINT,F.MAX_SIZE)*8)/1024.00)/1024.00) END MAX_SIZE
,DS.DRIVESPACE/1024.00 FREESPACEONDRIVE
INTO #SPACEANALYSISREPORT
FROM SYS.DATABASE_FILES F
INNER JOIN #DRIVESPACE DS ON DS.DRIVE = LEFT(F.PHYSICAL_NAME,1)
LEFT OUTER JOIN #LOGSPACE L ON L.DBNAME = DB_NAME() AND F.TYPE_DESC='LOG'
LEFT OUTER JOIN #LOGSPACE D ON D.DBNAME = DB_NAME() AND F.TYPE_DESC='ROWS'
LEFT OUTER JOIN
(SELECT DB_ID() DATABASE_ID, 'ROWS' TYPE_DESC,SUM(TOTAL_PAGES) RESERVED, SUM(USED_PAGES) USED FROM SYS.ALLOCATION_UNITS) A ON A.TYPE_DESC=F.TYPE_DESC
SELECT * FROM #SPACEANALYSISREPORT
DROP TABLE #LOGSPACE
DROP TABLE #DRIVESPACE
DROP TABLE #SPACEANALYSISREPORT
END