富贵资源网 Design By www.hznty.com
下面是创建一个sqlserver数据库的代码模板,加上一个创建表的模板。开发的时候可以拷贝过去直接改动一下就可以用了。
希望能帮上忙!
复制代码 代码如下:
USE [master]
GO
IF EXISTS(SELECT 1 FROM sysdatabases WHERE NAME=N'HkTemp')
BEGIN
DROP DATABASE HkTemp --如果数据库存在先删掉数据库
END
GO
CREATE DATABASE HkTemp
ON
PRIMARY --创建主数据库文件
(
NAME='HkTemp',
FILENAME='E:\Databases\HkTemp.dbf',
SIZE=5MB,
MaxSize=20MB,
FileGrowth=1MB
)
LOG ON --创建日志文件
(
NAME='HkTempLog',
FileName='E:\Databases\HkTemp.ldf',
Size=2MB,
MaxSize=20MB,
FileGrowth=1MB
)
GO
--添加表
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'Hksj_User') AND type in (N'U'))
BEGIN
CREATE TABLE Hksj_User
(
Id INT IDENTITY(1,1) NOT NULL,
SName NVARCHAR(20) NOT NULL,
SNickName NVARCHAR(20),
SPassWord NVARCHAR(30) NOT NULL,
DCreateDate DATETIME ,
SCreator NVARCHAR(20),
SEmail NVARCHAR(50),
SPhone NVARCHAR(50),
SIdentifyId NVARCHAR(30),
DLastTimeLogOn DATETIME
PRIMARY KEY CLUSTERED
(
Id ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
--添加注释
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'登录名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Hksj_User', @level2type=N'COLUMN',@level2name=N'SName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'邮箱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Hksj_User', @level2type=N'COLUMN',@level2name=N'SEmail'
希望能帮上忙!
复制代码 代码如下:
USE [master]
GO
IF EXISTS(SELECT 1 FROM sysdatabases WHERE NAME=N'HkTemp')
BEGIN
DROP DATABASE HkTemp --如果数据库存在先删掉数据库
END
GO
CREATE DATABASE HkTemp
ON
PRIMARY --创建主数据库文件
(
NAME='HkTemp',
FILENAME='E:\Databases\HkTemp.dbf',
SIZE=5MB,
MaxSize=20MB,
FileGrowth=1MB
)
LOG ON --创建日志文件
(
NAME='HkTempLog',
FileName='E:\Databases\HkTemp.ldf',
Size=2MB,
MaxSize=20MB,
FileGrowth=1MB
)
GO
--添加表
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'Hksj_User') AND type in (N'U'))
BEGIN
CREATE TABLE Hksj_User
(
Id INT IDENTITY(1,1) NOT NULL,
SName NVARCHAR(20) NOT NULL,
SNickName NVARCHAR(20),
SPassWord NVARCHAR(30) NOT NULL,
DCreateDate DATETIME ,
SCreator NVARCHAR(20),
SEmail NVARCHAR(50),
SPhone NVARCHAR(50),
SIdentifyId NVARCHAR(30),
DLastTimeLogOn DATETIME
PRIMARY KEY CLUSTERED
(
Id ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
--添加注释
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'登录名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Hksj_User', @level2type=N'COLUMN',@level2name=N'SName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'邮箱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Hksj_User', @level2type=N'COLUMN',@level2name=N'SEmail'
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...