一 创建表
1 基本语法
create table testFmj (
id int identity(1,1) , //identity表示自增列的意思,而int identity(1,1)表示从1开始递增,每次自增1。
name varchar(30) default(‘ABC’),
sex varchar(30),
age int default(20),
job varchar(30) default(‘hh’)
)
2 属性设置
设定自增模式:identity自增 从2开始,每次自增2—— id int identity(2,1)
设置默认值 :default默认——sex varchar(30) default (‘female’)
设置主键 : primary key主键——set id int indentity(1,1) primary key
设置非空: not null非空——name varchar(30) not null
二 删除表
1 sql语句
drop table testFmj 删除表内容、表定义、释放表空间(直接删除整个表,不能回滚)
truncate table testFmj 删除表内容,释放表空间,不删除表的定义和结构(一次性删除表中所有数据。不单独把操作日志保存。删除是不能恢复的,不会激活触发器,执行速度快。)
delete table testFmj (where XXX) 如果添加where语句,删除某些行。是一条一条的删除,并将删除操作作为记录保存,以便进行回滚操作。
2 三种删除方式的比较
1 表和索引所占的空间
delete不会减少表和索引所占的空间
truncate表和索引的空间恢复初始大小
drop表和索引占用空间全部删除
drop < truncate < delete
2 执行速度
drop > truncate > delete
要谨慎使用drop和truncate。
三 更新表
四 查询表