Oracle 表的常见操作

--创建表并指定表空间
create table goods(
id VARCHAR2(20) primary key,
name VARCHAR2(20) NOT NULL,
price NUMBER NOT NULL
)tablespace jzy;


--查看表属于哪个表空间
select table_name,tablespace_name from user_tables WHERE "LOWER"(table_name)='goods';


--查看表结构(只能在命令行窗口中执行,不能查询编辑器中执行)
DESC goods;


--增加列(无column关键字)
alter table goods add (stock number);


--修改列数据类型
alter table goods MODIFY(stock char);


--删除列(有column关键字)
alter table goods drop COLUMN stock;


--重命名列名
alter table goods rename column name to goodsName;


--将表移动到另外一个表空间
alter table goods move tablespace jzy;


--删除数据表和表之间的约束
drop table goods cascade constraints;


--更加列名获取所在的表名
select table_name from user_tab_cols where "LOWER"(column_name)='sno';


--利用已有的表创建一个另外一个一样的包 1<>1表示不要数据
create table student2 as select * from STUDENT where 1<>1;


--将student表中的数据插入student2表中
insert into student2 SELECT * from STUDENT where SSEX='男';

posted on 2013-08-08 20:50  you Richer  阅读(112)  评论(0编辑  收藏  举报