SQL基础(六)创建表

创建表 create table、select、union、rename

基本上Oracle、SQL-Server、MDB可以通用。
■基础篇
create table cxck.t订货 (
订货号 char (15) primary key,
产品号 varchar2(18),
订货数 number (9),
客户号 char (4),
操作员 char (7),
更新日期 char (10),
更新时间 char (8)
);

■复制创建
create table cxck.t订货1 as
select * from cxck.t订货 where 订货号 = '@';

create table cxck.t订货1 as
select * from cxck.t订货;

create table cxck.t订货1 as
select 订货号, 产品号 from cxck.t订货;

** 只复制表结构和数据。
** 不复制primary key 等约束。
** 可以通过alter table 追加primary key 等约束。
** 如果只创建空表,可以指定0纪录的where 查询条件。(例如:where 订货号 = '@' )

■复合创建
create table cxck.t订货1 as
select * from cxc.t订货
where 产品号 in
(select distinct 产品号 from cxck.t产品 where 产品号 = 'a001')
union all
select * from cxck.t订货
where 产品号 in
(select distinct 产品号 from cxck.t产品 where 产品号 = 'a001')
;
** 可以用union代替union all去掉重复纪录。

■表,视图等重命名
rename cxck.t订货1 to cxck.t订货2; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值