用户定义的表:
数据字典:
SELECT table_name FROM user_tables
SELECT DISTINCT object_type
FROM user_objects
SELECT *
FROM user_catalog
CREATE TABLE
语句CREATE TABLE [schema.]table
(column datatype [DEFAULT expr][, ...]);
必须指定:
创建表
DESCRIBE dept
或者 DESC dept
CREATE TABLE dept (deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13));
Table created.
CREATE TABLE table
[(column, column...)]
AS subquery;
create table emp1 as select * from employees;
create table emp2 as select * from employees where 1=2;
-- 创建的emp2是空表。
CREATE TABLE dept80 AS
SELECT
employee_id,
last_name,
salary * 12 ANNSAL,
hire_date
FROM
employees
WHERE
department_id = 80;
-- 验证创建的表
DESC dept80;
ALTER TABLE
语句使用 ALTER TABLE 语句可以:
使用 ALTER TABLE 语句追加, 修改, 或删除列的语
-- 追加
ALTER TABLE
TABLE_NAME ADD (
COLUMN datatype [ DEFAULT expr ] [, COLUMN datatype ]...
);
-- 修改
ALTER TABLE
TABLE_NAME MODIFY (
COLUMN datatype [ DEFAULT expr ] [, COLUMN datatype ]...
);
-- 删除
ALTER TABLE
TABLE_NAME DROP COLUMN column_name;
-- 重命名
ALTER TABLE
TABLE_NAME
RENAME COLUMM old_column_name TO new_column_name
ALTER TABLE dept80 ADD (job_id VARCHAR2(9));
-- 修改尺寸
ALTER TABLE dept80 MODIFY (last_name VARCHAR2(30));
-- 修改默认值
ALTER TABLE dept80 MODIFY (
salary number (9, 2) DEFAULT 1000
);
DROP COLUMN
子句删除不再需要的列.ALTER TABLE dept80 DROP COLUMN job_id;
RENAME COLUMN [table_name]
TO子句重命名列ALTER TABLE dept80 RENAME COLUMN job_id TO id;
DROP TABLE
语句不能回滚DROP TABLE dept80;
DELETE FROM emp2;
SELECT * FROM emp2;
ROLLBACK;
SELECT * FROM emp2;
TRUNCATE TABLE detail_dept;
RENAME dept TO detail_dept;
以上这些DDL的命令,操作外,皆不可回滚!
2024 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123