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='男';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章