Monday, September 12, 2011

Backup & Restores of the SQL Server Databases by using Lite Speed


Here are the some of Queries for taking the SQL Server Databases backups & Restore  by using the Lite Speed

Full & Diffencial backup
================
EXEC master.dbo.xp_backup_database @database='DBname'
,@filename='C:\DR_DIFF.BAK'
, @init= 1
, @with = 'DIFFERENTIAL'



T-log backup
========
EXEC master.dbo.xp_backup_log @database = 'DBname'
,@filename='C:\DR_LOG.BAK'
,@init = 1

Restore the database
----------
exec master.dbo.xp_restore_database @database = N'test' ,
@filename = N'Q:\Backup\Test_20130308.bak',
@filenumber = 1,
@with = N'STATS = 10',
@with = N'MOVE N''Test'' TO N''M:\data\Test.mdf''',
@with = N'MOVE N''Test_log'' TO N''H:\logs\Test_log.ldf''',
@affinity = 0,
@logging = 0
GO

Thanks&regards
As Reddy

Thursday, September 1, 2011

SQL Server Service Pack Version numbers



SQL Server 2000
----------------

SQL Server 2005
--------------------
-----------------

SQL 2008
----------

finding HIGH CPU using Query in SQL Server

finding the how CPU usage in SQL Server.which Query using high CPU usage..


SELECT st.text, r.cpu_time FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS st
ORDER BY cpu_time DESC

Thursday, August 25, 2011

Change the Owner of the Maintenance plan in SQL Server

SQL server 2008
------------------
update msdb.dbo.sysssispackages
set [ownersid] = suser_sid('sa')
where [name] = 'Maintence paln name'



SQL Server 2005
--------------------
--to find the name and owner of the maintenance plan
--select * from msdb.dbo.sysdtspackages90
--to find the sid you want to use for the new owner
--select * from sysusers

UPDATE
[msdb].[dbo].[sysdtspackages90]
SET
[ownersid] = 0x01
WHERE
[name] = 'MaintenancePlan'


SQL Server 2000 Maintenance Plan

--change the owner of a SQL Server 2000 Maintenance Plan UPDATE [msdb].[dbo].[sysdbmaintplans] SET [owner] = 'sa' WHERE [plan_name] = 'YOUR_MAINT_PLAN'

Wednesday, August 24, 2011

Import the Data from Excel Sheet to SQL server table



1) Fisrt I created Table in SQL

create table com(fname varchar(20),lname varchar(20))

2) I created Excel Sheet with name com.xls

3)given data below

4)i executed below script

INSERT INTO com ( fname, lname )

SELECT *

FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;Database=C:\Documents and Settings\All Users\Documents\com.xls',

'SELECT * FROM [Sheet1$]')

Tested
======

I got error while opening database properties






Cause
=====
for this errors two reasons
1)one is Database Owner is null
2)Original DBO Login was removed recently

Resolution
----------
first i checked the database owners

this is for all db's in a instace
-----------------------------
SELECT name,SUSER_SNAME(owner_sid) as DB_Owner
FROM sys.databases

out put
--------

I found probably Database Owner is NUll..

Then i changed Database Owner to SA


USE DB_Name
go
EXEC sp_changedbowner 'sa'

after that i am able to open the Database Properties


Query for finding the which Service Pack installed on SQL Server

select serverproperty('productlevel')