Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sunny_10
Yak Posting Veteran
72 Posts |
Posted - 2013-04-11 : 06:21:05
|
Hi I want to Create Database & Tables using Stored Procedure . It should also check if Database already exists or not if not then it should create . Secondly i want to pass Database Name & MDF file as parameters.Thanks |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-11 : 07:39:15
|
[code]--Script for create Database by passing Database name and .mdf file path nameDECLARE @DBName VARCHAR(30) = 'test12', @MDFFileName VARCHAR(100)DECLARE @sql VARCHAR(MAX)=''SET @sql ='if exists (select name from sys.databases where name=''' + @DBName +''') drop database ' + @DBName +'; create database ' +@DBName +' on primary (filename= '+ @MDFFileName + ' );'--PRINT (@SQL);EXEC (@sql);[/code]To create tables, will you want to pass table names and columns? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-12 : 05:04:23
|
quote: Originally posted by bandi
--Script for create Database by passing Database name and .mdf file path nameDECLARE @DBName VARCHAR(30) = 'test12', @MDFFileName VARCHAR(100)DECLARE @sql VARCHAR(MAX)=''SET @sql ='if exists (select name from sys.databases where name=''' + @DBName +''') drop database ' + @DBName +'; create database ' +@DBName +' on primary (filename= '''+ @MDFFileName + ''' );'--PRINT (@SQL);EXEC (@sql); To create tables, will you want to pass table names and columns?
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|