Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

19 July 2011

how to change the database name in sqlserver using query

ALTER DATABASE databasename MODIFY NAME = newdatabasename

how to Insert data of one database table to another database table

INSERT INTO Database2..Table1 SELECT * FROM Database1..Table1

How to restore and backup database in sqlserver using query

For BackUp:
backup database mydb to disk = 'c:\mydb.bak'


For Restore:
restore database mydb from disk = 'c:\mydb.bak'

how to make nvarchar id auto incerement (1) function in sqlserver

create function idincr() returns nvarchar(50)
as begin
declare @id int, @cid nvarchar(50), @did int
set @id=(select count(*) from tblcust)
if(@id>0)
begin
set @did= (select max(cast(substring(custid,2,len(custid))as int))from tblcust)+1;
set @cid='A'+cast(@did as nvarchar(50))
end
else 
set @cid='A1'
return @cid
end

Go

select dbo.idincr()

Go

how to change the database name in sqlserver using query

ALTER DATABASE databasename MODIFY NAME = newdatabasename

how to Insert data of one database table to another database table

INSERT INTO Database2..Table1 SELECT * FROM Database1..Table1

How to restore and backup database in sqlserver using query

For BackUp:
backup database mydb to disk = 'c:\mydb.bak'


For Restore:
restore database mydb from disk = 'c:\mydb.bak'

How to copy table structure and data into another database using query

select * into destinationdb..destinationtable from sourcedb..sourcetable

18 July 2011

how to restore database from sqlserver2008 to sqlserver2005

Right click on database of sqlserver2008 that u want to restore-->
Tasks-->
GenerateScripts-->
Next-->
Select Particular database that u want to restore-->
Next-->
Next-->
Select Tables and UserDefined Functions-->
Next-->
Select Tables and Functions-->
Next-->
Select Script to New QueryWindow-->
Next-->
Finish.

It gives a long Query. Copy It, Then execute in Sqlserver2005.
It's working...

How to copy table structure and data into another database using query

select * into destinationdb..destinationtable from sourcedb..sourcetable

how to restore database from sqlserver2008 to sqlserver2005

Right click on database of sqlserver2008 that u want to restore-->
Tasks-->
GenerateScripts-->
Next-->
Select Particular database that u want to restore-->
Next-->
Next-->
Select Tables and UserDefined Functions-->
Next-->
Select Tables and Functions-->
Next-->
Select Script to New QueryWindow-->
Next-->
Finish.

It gives a long Query. Copy It, Then execute in Sqlserver2005.
It's working...