Created
October 26, 2015 14:27
-
-
Save pallid/1f6dbeea492c61352a40 to your computer and use it in GitHub Desktop.
CreanNbase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @tmp table(db varchar(100) ) | |
declare @paths varchar(100) | |
set @paths = 'D:\SQL_BASE\MSSQL11.MSSQLSERVER\MSSQL\DATA\' | |
insert into @tmp | |
select 'db1' union | |
select 'db2' union | |
select 'db3' union | |
select 'db23213' union | |
select 'db4' | |
--select * from @tmp | |
declare @name varchar(100) | |
declare @sql varchar(max) | |
declare mycursor cursor for | |
select db from @tmp | |
open mycursor | |
fetch next from mycursor into @name | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
set @sql='CREATE DATABASE '+@name | |
+' ON | |
PRIMARY (NAME='+@name+'Data, | |
FILENAME='''+@paths+@name+'_data.mdf'', | |
SIZE=200, | |
FILEGROWTH=200 ) | |
LOG ON ( | |
NAME='+@name+'Log, | |
FILENAME='''+@paths+@name+'_log.ldf'', | |
SIZE=1, | |
MAXSIZE=4096, | |
FILEGROWTH=50 | |
) ' | |
select @sql | |
--exec(@sql) | |
FETCH NEXT FROM mycursor | |
INTO @name | |
END | |
close mycursor | |
deallocate mycursor | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment