必须会的SQL语句(二) 创建表、修改表结构、删除表


1.创建数据库表

--使用哪个数据库,如果不写这一句是默认的数据库,也可以用鼠标选当前数据库
use testDB
--创建表
  Create Table tablename
  (
     --id表示字段名
     --int 数据类型
     --primary key 主键
     --not null 非空
     --identity(1,1)初始值是1 每次自增长1
     id int primary key not null identity(1,1),
     --unique 唯一
     name varchar(20) not null unique
  )

2.删除表
Drop table 表名
 
3.修改表结构

--增加列
Alter table 表名
Add 列名 类型
--删除列
Alter table 表名
  drop cloumn 列名
--修改列,修改列类型
Alter table 表名
Alter column 列名 type


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3