
use Test --进入需要建表的数据库
if exists(select * from sysobjects where name='MyTable')--表是否已经存在
drop table MyTable--存在就删除
CREATE TABLE MyTable --建表
(
ID INT IDENTITY(1,1) PRIMARY KEY , --IDENTITY(1,1) 是指设定一个字段的值从1开始,以1为单位增量的自动增加 PRIMARY KEY 设置为主键(索引)
NAME VARCHAR(10) NOT NULL, -- NOT NULL 不能为空
Age CHAR(3) NOT NULL
)