alter table rename talblename、columnname、indexname、constraintsname
重命名表名、字段名、索引名、约束名
SQL> CREATE TABLE test1 (
2 col1 NUMBER(10) NOT NULL,
3 col2 VARCHAR2(50) NOT NULL);
Table created.
SQL> ALTER TABLE test1 ADD (
2 CONSTRAINT test1_pk PRIMARY KEY (col1));
Table altered.
SQL> DESC test1
Name Null? Type
——————– ——– ——————–
COL1 NOT NULL NUMBER(10)
COL2 NOT NULL VARCHAR2(50)
SQL> SELECT constraint_name
2 FROM user_constraints
3 WHERE table_name = ‘TEST1’
4 AND constraint_type = ‘P’;
CONSTRAINT_NAME
——————————
TEST1_PK
1 row selected.
SQL> SELECT index_name, column_name
2 FROM user_ind_columns
3 WHERE table_name = ‘TEST1’;
INDEX_NAME COLUMN_NAME
——————– ——————–
TEST1_PK COL1
1 row selected.
SQL> — Rename the table, columns, primary key
SQL> — and supporting index.
SQL> ALTER TABLE test1 RENAME TO test;
Table altered.
SQL> ALTER TABLE test RENAME COLUMN col1 TO id;
Table altered.
SQL> ALTER TABLE test RENAME COLUMN col2 TO description;
Table altered.
SQL> ALTER TABLE test RENAME CONSTRAINT test1_pk TO test_pk;
Table altered.
SQL> ALTER INDEX test1_pk RENAME TO test_pk;
Index altered.
SQL> DESC test
Name Null? Type
——————– ——– ——————–
ID NOT NULL NUMBER(10)
DESCRIPTION NOT NULL VARCHAR2(50)
上一篇: linux du 显示路径下各子目录大小
下一篇: exp query 导出加where条件
目前这篇文章有3条评论(Rss)评论关闭。