Create, rename and drop a database in sql server …
Create database
See syntax below for the CREATE DATABASE statement.
Create NORTHWIND database
1> use master
2> go
1> create database [NORTHWIND]
2> on ( name = N'NORTHWIND_dat',
3> filename = N'C:\\mssql\\data\\iDEFAULT\\NORTHWIND\\NORTHWIND_01.mdf' ,
4> size = 10,
5> filegrowth = 1,
6> maxsize = 1024
7> )
8> log on ( name = N'NORTHWIND_log',
9> filename = N'C:\\mssql\\tlog\\iDEFAULT\\NORTHWIND\\NORTHWIND_01.ldf' ,
10>
Read more →
Restore SQL Server database with TSQL
Recently I had troubles restoring a database in my SQL Server 2005 instance (SP3). I used the ‘wizard’ in the SQL Server Enterprise manager but after I got the message ‘restore completed successfully’ the database hung in ‘Restoring’ state, blocking connections.
I decided the try to restore the database with T-SQL, with T-SQL the restore completed successfully! Another advantage of using T-SQL is that T-SQL gave more logging. This logging shows me that the BAK file (delivered from a third party) is not a SQL Server 2005 backup but presumably a SQL Server 2000 database backup …
DECLARE @BackupFile varchar(8000), @sql varchar(8000) SET @BackupFile = 'E:\DB2000.BAK' SET @sql = 'RESTORE DATABASE ADB01 FROM DISK = ''' + @backupfile + ''' WITH FILE = 1, MOVE N''DB2000_dat'' TO N''E:\mssql\data\ADB01\ADB01_01.mdf'', MOVE N''DB2000_log'' TO N''F:\mssql\tlog\ADB01\ADB01_01.ldf'', NOUNLOAD,Read more →