创建表
创建一个学生表
create table student(
sno char(10),
sname char(10) unique,
sex char(2),
age numeric(3),
department char(8),
bplace char(10),
primary key(sno)
);
修改表
增加列
student表中增加一个stel列
alter table student add stel char(12);
删除列
student表中删除stel列
alter table student drop column stel;
修改列
修改字段长度, 将student表中的宽度调整为10
alter table student alter column department char(10);
删除表
删除student表
drop table student;
/*注意*/
/*在sql server中不允许后面追加cascade 和 restrict关键字*/
索引
建立索引
/*建立索引 desc表示降序*/
create unique index sno_index on student (sno desc);
create index s_index on student (age);
删除索引
drop index student.s_index;
/*遇到一个坑,就是表名和索引名之间要有一个点*/
查询表
单表查询
查询所有字段