USE master
GO
if exists (select * from sysdatabases where name='MyDatabase')
drop database Chinthaka
goDECLARE @device_directory NVARCHAR(520)
SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1EXECUTE (N'CREATE DATABASE MyDatabase
ON PRIMARY (NAME = N' 'MyDatabase' ', FILENAME = N ' ' ' + @device_directory + N'MyDatabase.mdf' ')
LOG ON (NAME = N' 'MyDatabase_log' ', FILENAME = N ' ' ' + @device_directory + N'MyDatabase.ldf ' ' ) ' )
goexec sp_dboption 'MyDatabase','trunc. log on chkpt.','true'
exec sp_dboption 'MyDatabase','select into/bulkcopy','true'
GOset quoted_identifier on
GOUSE [MyDatabase]
GO
**Replace MyDatabase With your database name
Save about code in a sql file named Script
open command prompt & execute this command
sqlcmd -S CHINTHAKA_D\SQLEXPRESS -i "E:\Desktop\Script.sql"
Comments
Good work
Post a Comment