在关系型数据库中,表被看作一个关系,表中的每个列是关系中的属性,是一个不可再分割的基本单位,表中的行对应一个元组。
①、创建表
create table <表名>(<列名><数据类型>[约束]);
数据类型:
SCOTT@myh>create table stu (id number(12) primary key,
2 name varchar(20),
3 age number(3));
#通过子查询的方式创建表:
SCOTT@myh>create table test as select * from dept;
②、表的修改
#增加列 关键字add
SCOTT@myh>alter table stu add (tel number(11));
Table altered.
#删除列 关键字drop
SCOTT@myh>alter table stu drop column age;
Table altered.
#修改列的定义 关键字modify
SCOTT@myh>alter table stu modify (id number(4));
Table altered.
#将一个列设置为不可用 关键字set unused。设置为unused的列虽然逻辑上看不到,但是物理上是存在的。
#然后再删除不可用列。
SCOTT@myh>alter table stu set unused column tel;
Table altered.
#修改列名 关键字 rename column <> to <>
SCOTT@myh>alter table stu rename column name to stu_name;
Table altered.
#将表设置为只读状态
SCOTT@myh>alter table stu read only;
#设置为可写状态
SCOTT@myh>alter table stu read write;
③、表的删除,将表结构和表数据全部都删除。
SCOTT@myh>drop table stu;
Table dropped.