SqlServer创建数据库和表的语法

 1创建数据库表 
 2use master --切换到master数据库 
 3go 
 4--检测是否存在同名的数据库 
 5if exists(select 1 from sysdatabases where name = 'tour'
 6begin 
 7  drop database tour 
 8end 
 9go 
10create database tour 
11on --数据文件 
12
13  name = 'tour_mdf'--数据文件逻辑名 
14  filename = 'D:\tour.mdf',--数据文件存放路径 
15  size = 1MB,--初始大小 
16  maxsize = 10MB,--最大大小 
17  filegrowth = 1MB--增长速度 
18
19log on --日志文件 
20
21  name = 'tour_ldf'--日志文件逻辑名 
22  filename = 'D:\tour.ldf',--日志文件存放路径 
23  size = 1MB,--初始大小 
24  maxsize = 10MB,--最大大小 
25  filegrowth = 1MB--增长速度 
26
27go 
28use tour 
29go 
30创建数据库表 
31if exists(select * from sysobjects where name='stuInfo'drop table stuInfo 
32create table   stuInfo    /*-创建学员信息表-*/ 
33
34
35stuNo   varchar(6not null unique,   --学号,非空(必填) 
36stuName  varchar(20not null ,  --姓名,非空(必填) 
37stuAge  int  not null,  --年龄,INT类型默认为4个字节 
38stuID  NUMERIC(18,0),     --身份证号 
39stuSeat   int  IDENTITY (1,1),   --座位号,自动编号 
40stuAddress   text   --住址,允许为空,即可选输入 
41
42go 
43
44if exists(select * from sysobjects where name='stuMarks'drop table stuMarks 
45create table  stuMarks 
46
47ExamNo  varchar(6)  not null foreign key references stuInfo(stuNo) ,  --考号 
48stuNo  varchar(6not null,   --学号 
49writtenExam  int  not null,  --笔试成绩 
50LabExam  int  not null    --机试成绩 
51
52go 
53
54if exists(select * from sysobjects where name='users'drop table users 
55create table users 
56
57    userID int not null primary key identity(1,1), 
58    userName varchar(255not null unique
59    userPWD varchar(255not null
60    userAge int
61    userBirthDay datetime
62    userEmail varchar(255
63
64go 

posted on 2010-11-02 21:48 麟德 阅读(498) 评论(0)  编辑  收藏 所属分类: SQLServer


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿

随笔分类(2)

随笔档案(2)

文章分类(23)

文章档案(23)

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜