建表语法
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