随笔 - 13, 文章 - 0, 评论 - 3, 引用 - 0
数据加载中……

实例演示Oracle的表与列

添加表中的列
ALTER TABLE major ADD majorRank number(3);
ALTER TABLE major ADD createDate DATE DEFAULT SYSDATE NOT NULL;
ALTER TABLE major ADD peopleNum number(4) CONSTRAINT ck_peopleNum CHECK(peopleNum > 30);

查看表中的列:
SELECT * FROM USER_TAB_COLS WHERE TABLE_NAME = 'MAJOR';

删除列:
ALTER TABLE major DROP COLUMN majorRank;
ALTER TABLE major DROP (majorRank,peopleNum);

重命名列:
ALTER TABLE major RENAME COLUMN createDate TO foundDate;

设置列为UNUSED:
ALTER TABLE major SET UNUSED COLUMN foundDate;
ALTER TABLE major SET UNUSED (majorRank,CreateDate,peopleNum);

删除表:
DROP TABLE major;

恢复被删除的表
FLASHBACK TABLE major TO BEFORE DROP;

根据另外一个表创建表
CREATE TABLE newTable AS SELECT * FROM STUDENT;

添加表和列的注释
COMMENT ON TABLE newTable is ‘Copy student struct’;

SELECT * FROM user_tab_comments where table_name = 'NEWTABLE';

COMMENT ON COLUMN newTable.studentID is 'Copy student.studentID';

SELECT * FROM user_col_comments where table_name = 'NEWTABLE';

删除表:
DROP TABLE newTable;

清空回收站:
PURGE RECYCLEBIN;

posted on 2009-06-02 22:44 五味杂陈 阅读(359) 评论(0)  编辑 收藏 引用 所属分类: Oracle


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理