创建数据表

来源:互联网 发布:金和网络 陈耀泉 编辑:程序博客网 时间:2024/05/29 03:07

语法:
create table 表名
(
字段名称 字段类型 字段特征(是否为null,默认值 标识列 主键 唯一键 外键 check约束),
字段名称 字段类型 字段特征(是否为null,默认值 标识列 主键 唯一键 外键 check约束)
)
创建老师表Teacher :Id、Name、Gender、Age、Salary、Birthday

use Schoolif exists(select * from sysobjects where name='Classes')  drop table Classescreate table Classes( Classid int identity(1,1), ClassName nvarchar(50) not null )if exists(select * from sysobjects where name='teacher')  drop table teachercreate table Teacher( Id int identity(1,1),--可以同时创建多个特征,用空格 分隔开。 identity是标识列,第一个参数是种子,第二个是增量Name nvarchar(50)  not null,-- not null标记它的值不能为null--不能不填写ClassId int not null, Gender bit not null,Age int   ,Salary money, --如果不标记为 not null.那么就相当于标记了nullBirthday datetime  )
0 0