码迷,mamicode.com
首页 > 数据库 > 详细

MS SQL Server 建库建表

时间:2016-06-23 22:19:59      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:


CREATE DATABASE Test

use Test

--创建用户类型表
CREATE TABLE UserType (
ID INT NOT NULL identity(1,1) primary key,
TypeName VARCHAR(200) DEFAULT NULL ,

TypeDescription VARCHAR(200) DEFAULT NULL ,
)
exec sys.sp_addextendedproperty @name=‘MS_Description‘,@value= ‘自增长主键‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserType‘,@LEVEL2TYPE=‘COLUMN‘,@level2name=‘ID‘
exec sys.sp_addextendedproperty @name=‘MS_DESCRIPTION‘,@value=‘用户类型名称‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserType‘,@level2type=‘column‘,@level2name=‘TypeName‘
exec sys.sp_addextendedproperty @name=‘ms_description‘,@value=‘用户类型描述‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserType‘,@level2type=‘coloum‘,@level2name=‘TypeDescription‘

-- 创建一个用户信息数据表

CREATE TABLE UserInfo (
ID INT NOT NULL identity(1,1) primary key,
UserName VARCHAR(200) DEFAULT NULL ,
UserLogin VARCHAR(200) DEFAULT NULL ,
UserPassword VARCHAR(200) DEFAULT NULL ,
UserEmail VARCHAR(100) DEFAULT NULL ,
UserType int DEFAULT NULL ,
CONSTRAINT userinfo_ibfk_1 FOREIGN KEY (UserType) REFERENCES usertype (ID)
)
exec sys.sp_addextendedproperty @name=‘MS_Description‘,@value= ‘自增长主键‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@LEVEL2TYPE=‘COLUMN‘,@level2name=‘ID‘
exec sys.sp_addextendedproperty @name=‘MS_DESCRIPTION‘,@value=‘用户姓名‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@level2type=‘column‘,@level2name=‘UserName‘
exec sys.sp_addextendedproperty @name=‘ms_description‘,@value=‘用户登录名‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@level2type=‘coloum‘,@level2name=‘UserLogin‘
exec sys.sp_addextendedproperty @name=‘MS_Description‘,@value= ‘密码‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@LEVEL2TYPE=‘COLUMN‘,@level2name=‘UserPassword‘
exec sys.sp_addextendedproperty @name=‘MS_DESCRIPTION‘,@value=‘电子邮箱‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@level2type=‘column‘,@level2name=‘UserEmail‘
exec sys.sp_addextendedproperty @name=‘ms_description‘,@value=‘用户类型‘,@level0type=‘schema‘,@level0name=‘dbo‘,@level1type=‘table‘,@level1name=‘UserInfo‘,@level2type=‘coloum‘,@level2name=‘UserType‘


MS SQL Server 建库建表

标签:

原文地址:http://www.cnblogs.com/zhaochengshen/p/5612269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!