--1 创建表
--使用子查询创建表
--复制表
create table t1 as (
select employee_id,last_name,salary from employees
);
select * from t1;
-- 只复制表结构,没有数据
create table t2 as(select * from employees where 1=2)
select * from t2;
create table t3 as (
select * from employees where department_id=30);
select * from t3;
---------------------------------------------------
--2 修改表 alter table
--2.1追加列 add
alter table t1 add (job varchar(20));
select * from t1;
--2.2 modify 修改列数据类型、尺寸和默认值。
--默认只对修改后的数据有用
alter table t1 modify(job number(10) default 100);
--2.3重命名列 rename column
alter table t1 rename column employee_id to id;
select * from t1;
--2.4 删除列 drop column
alter table t2 drop column employee_id;
select * from t2;
---------------------------------------------------
--3 drop table 删除表
drop table t2;select * from t2;
--4 truncate table 清空表
select * from t3;
truncate table t3;
select * from t3;
--5 rename <旧表名> to <新表名> 修改对象名称
rename t1 to table1;
select * from table1;
Oracle创建表DDL
最新推荐文章于 2025-05-29 14:59:57 发布
本文介绍了如何使用SQL创建表,包括子查询和复制表的不同方式,随后展示了如何通过ALTER TABLE进行列的增删改,以及表结构的修改。后续内容涵盖了DROP TABLE删除表、TRUNCATE TABLE清空表和RENAME TABLE重命名表的操作。
1172

被折叠的 条评论
为什么被折叠?



