Thursday 19 May 2011

Change Collation Of Database

USE [master]

ALTER DATABASE [DbName]  SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

GO
ALTER DATABASE [DbName] COLLATE SQL_Latin1_General_CP1_CI_AS
GO
ALTER DATABASE [DbName] SET RECOVERY FULL WITH NO_WAIT
GO

Go
ALTER DATABASE [DbName]  SET MULTI_USER 
GO

Sql X Types

C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
IF = Inlined table-function
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
R = Rule
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
V = View
X = Extended stored procedure

Comparing Tables For Difference Version

Create table #nik
(
    table_Name Varchar(300),
    Column_Name Varchar(300)
)
Create Table #Temp 
(
    Table_Name Varchar(300)
) 

Insert Into #nik Select TABLE_NAME ,Column_Name From dbName.Information_Schema.columns 
Where Column_Name Not IN
(Select Column_Name From dbName2.Information_Schema.columns) 
Select * From #nik 

Select * From #nik  Where table_Name Not in (Select table_Name from #Temp)
Insert Into #Temp Values('Table')
Select * From #Temp 

Tuesday 3 May 2011

Rename Computer Name When Sql Server Already Installed

To rename a computer that hosts a stand-alone instance of SQL Server
•    For a renamed computer that hosts a default instance of SQL Server, run the following procedures:

sp_dropserver <old_name>
GO
sp_addserver <new_name>, local
GO
Restart the instance of SQL Server.
•    For a renamed computer that hosts a named instance of SQL Server, run the following procedures:

sp_dropserver <'old_name\instancename'>
GO
sp_addserver <'new_name\instancename'>, local
GO
Restart the instance of SQL Server.
 After the Renaming Operation
________________________________________
After a computer has been renamed, any connections that used the old computer name must connect by using the new name.
To verify that the renaming operation has completed successfully
•    Select information from either @@SERVERNAME or sys.servers. The @@SERVERNAME function will return the new name, and the sys.servers table will show the new name. The following example shows the use of @@SERVERNAME.

SELECT @@SERVERNAME AS 'Server Name'