创建表
- varchar(max) 类型,最大容量2G的字符,只是直接用sql语句查询时会被截断不能完整显示
- primary key (主属性)主键约束
- check 属性的范围约束
- unique 唯一性约束
create table User(
userid int primary key not null,
nick varchar(64) not null,
age int not null check(age >= 0 and age <= 120) default(0),
sex int not null check(sex >= 0) default(0)
)
修改表定义
alter table <表名>
add column <列名> <数据类型> [约束] --添加列
drop column <列名> [ cascade | restrict ] --删除列
drop constraint <约束名称> [ cascade | restrict ] --删除约束
alter column <列名> <数据类型> --修改列
索引
- 创建索引提高查询效率,同时会降低添加,修改,删除的效率。
create [unique] [cluster] index index_name on User age asc --创建索引升序
create [unique] [cluster] index index_name on User age desc --创建索引降序
create [unique] [cluster] index index_name on User name asc, age desc --创建索引
drop index index_name --删除指定名称的索引
alter index index_name rename to index_name2 --修改索引名称