ITPub博客

首页 > 数据库 > Oracle > SQL基础(六)创建表

SQL基础(六)创建表

原创 Oracle 作者:cxck 时间:2007-03-20 14:03:40 0 删除 编辑
创建表 create table、select、union、rename[@more@]

基本上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;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/174388/viewspace-905970/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    38
  • 访问量
    74699