创建SQL数据库表
- 语法:
create table 表名称
(
字段名称 字段类型 字段特征(标识符 是否空值 主键 唯一值 默认值 check约束) ,
字段名称 字段类型 字段特征(标识符 是否空值 主键 唯一值 默认值 check约束)
) - 创建Teacher表 字段:Id、Name、Gender、Age、Salary、Birthday
use TestSchool --切换TestSchool数据库
if exists(select * from sysobjects where name = 'Teacher') --如果存在表Teacher则删除
drop table Teacher
go
create table Teacher --创建Teacher表
(
Id int identity(1,1) primary key, --设置标识列、主键 identity(标识种子,标识增量)
Name nvarchar(50) not null, --设置不为空 nvarchar不设置字符长度,默认为1个字符长度
Gender bit not null, -- 男为1,女为0
Age int check(age > 0 and age <= 100) not null,
Salary money, --当一个字段为null时,可以写也可以不写
Birthday datetime not null default('2000-10-10')
)