--创建数据库一般分三步
--1. 创建数据库设备
--2. 创建数据库
--3. 设置或创建数据库所属用户
--数据库设备:my_dev,数据库名字:my_database,用户名密码:scott/123456
------------------------创建数据库设备-----------------------------------------
USE master
go
DISK INIT NAME='my_dev', PHYSNAME='C:\SAP\data\my_dev.dat', SIZE='100M'
go
EXEC sp_diskdefault 'my_dev',defaultoff
go
IF EXISTS (SELECT * FROM master.dbo.sysdevices WHERE name='my_dev')
PRINT '<<< CREATED DATABASE DEVICE my_dev >>>'
ELSE
PRINT '<<< FAILED CREATING DATABASE DEVICE my_dev >>>'
------------------------创建数据库-----------------------------------------
go
CREATE DATABASE my_database ON my_dev='50M'
go
IF DB_ID('my_database') IS NOT NULL
PRINT '<<< CREATED DATABASE my_database >>>'
ELSE
PRINT '<<< FAILED CREATING DATABASE my_database >>>'
go
------------------------设置数据库所属用户-----------------------------------------
--USE my_database
--go
--EXEC sp_changedbowner 'scott'
--go
------------------------创建数据库所属用户-----------------------------------------
USE master
go
EXEC sp_addlogin 'scott','123456','my_database','us_english',"userForScott",null,6,null
go
EXEC sp_role 'grant','navigator_role','scott'
go
EXEC sp_role 'grant','oper_role','scott'
go
EXEC sp_role 'grant','replication_role','scott'
go
EXEC sp_role 'grant','sa_role','scott'
go
EXEC sp_role 'grant','sso_role','scott'
go
EXEC sp_role 'grant','sybase_ts_role','scott'
go
USE my_database
go
EXEC sp_adduser 'scott','scott','public'
go
来源:oschina
链接:https://my.oschina.net/feiyang2017/blog/3189979