我也来分点"脏",代码几乎都是抄wgzhang的,后面的有改进.
PS : if not exists (select * from sysusers where name = N'GZ'
and uid < 16382) 的 16382 是什么意思?
CODE :
USE master
GO
CREATE DATABASE GZDATA
ON
( NAME = GZ_DATA,
FILENAME = 'c:/GZ_DATA.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = 'GZ_log',
FILENAME = 'c:/GZ_log.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )
GO
if not exists (select * from master..syslogins where name = N'GZ')
BEGIN
declare @logindb nvarchar(132), @loginlang nvarchar(132)
select @logindb = N'GZDATA', @loginlang = N'us_english'
if @logindb is null or not exists (select * from master..sysdatabases where name = @logindb)
select @logindb = N'master'
if @loginlang is null or (not exists (select * from master..syslanguages where name = @loginlang) and @loginlang <> N'us_english')
select @loginlang = @@language
-- exec sp_addlogin N'GZ', null, @logindb, @loginlang
exec sp_addlogin N'GZ', N'xxgs', @logindb, @loginlang
END
GO
if not exists (select * from sysusers where name = N'GZ' and uid < 16382)
USE GZDATA
EXEC sp_grantdbaccess N'GZ', N'GZ'
GO
USE GZDATA
exec sp_addrolemember N'db_owner', N'GZ'
GO
use master
exec sp_dboption N'GZDATA', N'trunc. log', N'true'
exec sp_dboption N'GZDATA', N'bulkcopy', N'true'
exec sp_dboption N'GZDATA', N'auto create statistics', N'true'
exec sp_dboption N'GZDATA', N'auto update statistics', N'true'
exec sp_dboption N'GZDATA', N'autoshrink', N'true'
GO
use GZDATA
exec sp_dbcmptlevel N'GZDATA'
GO
use GZDATA
GRANT CREATE TABLE , CREATE VIEW , CREATE PROCEDURE ,
DUMP DATABASE , CREATE DEFAULT , DUMP TRANSACTION ,
CREATE RULE TO [GZ]