数据库空间创建

SET @dbfilename = '%$dbfilename$%123.mdf'
SET @dbfilesize = '400'
SET @logfilename = '%$logfilename$%1234.ldf'
SET @logfilesize = '50'

SET @dbname = 123B'
SET @dbdevname = @dbname + 'DEV'
SET @dblogname = @dbname + 'LOG'

DECLARE @sql varchar(800)
SET @sql = 'Drop Database ' + @dbname
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = @dbname)
BEGIN
    PRINT ''
    PRINT 'Deleting existing database ' + @dbname + '...'
    PRINT ''
    exec(@sql)
END

IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = (@dbname))
BEGIN
SET @sql = 'CREATE DATABASE ' + @dbname + ' ON
    (NAME = N''' + @dbdevname + ''',
    FILENAME =''' + @dbfilename +''',
    SIZE = ' + cast(@dbfilesize as char(5))+ ',
    FILEGROWTH = 10%)
    LOG ON
    (NAME = N''' + @dblogname + ''',
    FILENAME =''' + @logfilename +''' ,
    SIZE = ' + cast(@logfilesize as char(5))+',
    FILEGROWTH = 10%)'
PRINT ''
PRINT 'Creating database ' + @dbname + '.....'
PRINT ''
PRINT 'Parameter of ' + @dbname + ' database :'
PRINT 'Database file position is :'+@dbfilename
PRINT 'Database file size is :'+CAST(@dbfilesize as CHAR(5))
PRINT 'Database log file position is :'+@logfilename
PRINT 'Database log file size is :'+CAST(@logfilesize as char(5))
PRINT ''
EXEC(@sql)
IF (@@error <> 0)
           RAISERROR('Unable to create database. ZXC_BSS3G_PM_DB.SQL terminating.', 20, 127) WITH LOG

PRINT 'Create database ' + @dbname + ' Completed!'
END
GO

exec sp_dboption 123B','autoshrink','true'
go
 
exec sp_dboption 333B','trunc. log on chkpt.','true'
go

你可能感兴趣的:(数据库空间创建)