个人笔记 -- Oracle(二)
目录
创建表
create table 表名
(
字段名 数据类型,
stname varchar2(10) not null ,
stsex char(3),
stdate date
stgrade varchar(5) default '一年级'
);
查询当前用户下的所有表
表:user_tables
select * from user_tables;
查看表结构
表:user_tab_cols、user_tab_columns
select * from user_tab_columns where table_name='大写表名'
复制表结构以及数据(不会复制约束)
create table emp_form as select * from emp;
复制部分数据
create table 表1 as select 字段1, 字段2 from 表2;
复制数据
insert into 表1(select * from 表2)
insert into 表1(字段1,字段2) (select 字段1,字段2 from 表2)
修改表名
alter table TEST rename to TEST1;
查看创建表的列 表:user_tab_columns
select * from user_tab_columns where table_name = 'STUDENT';
给表添加备注
comment on table 表名 is '备注名';
改变表结构(添加列)
alter table student add (stwy number(11));
修改列名
alter table student rename column stwy to st_class;`
修改表结构 (字段)
alter table student modify (stsex char(4),+);
删除表结构(字段)
alter table abc drop (b,+);
alter table abc drop column a;
删除表数据内容,能回滚
delete from 表名 where 条件;
删除表数据内容,不能回滚
truncate table emp_form;
删除表(慎用)
drop table emp_form;