数据库表的创建

建表语法

create table 表名

  字段1 数据类型 列的特征,

  字段2 数据类型 列的特征 

列的特征包含内容

1.是否为空 null / not null

2.是否为标识列 identity()

3.是否有默认值 

4.是否为主键 primary key ,主键是实体的唯一标识,保证实体不被重复。

 1 use StudentManageDB
 2 go
 3 
 4 --创建学生表
 5 if exists(select* from sysobjects where name='Students')
 6 drop table Students
 7 go
 8 
 9 create table Students
10 (
11     StudentId int identity(10000,1),
12     StudentName varchar(20) not null,
13     Gender char(2)not null,
14     Birthday datetime not null,
15     StudentIdNo numeric(18,0)not null,
16     Age int not null,
17     phoneNumber varchar(50),
18     StudentAddress varchar(500),
19     ClassId int not null--班级外键
20     
21 )
22 go
23 
24 --创建班级表
25 if exists(select* from sysobjects where name='StudentClass')
26 drop table StudentClass
27 go
28 
29 create table StudentClass
30 (
31     ClassId int primary key,
32     ClassName varchar(20)not null
33     
34 )
35 go 
36 
37 --创建成绩表
38 if exists(select* from sysobjects where name='ScoreList')
39 drop table ScoreList
40 go
41 
42 create table ScoreList
43 (
44     Id int identity(1,1) primary key,
45     StudentId int not null, --学号外键
46     CSharp int null,
47     SQLServer int null,
48     UpdateTime datetime not null
49 )
50 go 
51 
52 --创建管理员表
53 if exists(select* from sysobjects where name='Admins')
54 drop table Admins
55 go
56 
57 create table Admins
58 (
59     LoginId int identity(1000,1) primary key,
60     LoginPwd varchar(20) not null    
61 )
62 go 

 

转载于:https://www.cnblogs.com/Linglinlin/p/7154050.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值