-- 1.基本表操作表
drop table user1;
create table user1(
id number(5,3) not null, -- (N,M) N:一共幾位,M:小數(shù)后幾位
name varchar2(10) not null,
tel number(11,0) not null
);
truncate table user1;
insert into user1(id,name,tel) values(23.456,'aaa',22);
insert into user1(id,name,tel) values((select max(id) from user1)+1,'aaa',22);
select * from user1;
-- 2.創(chuàng)建表
create table user2 as select * from user1; -- 復(fù)制全部字段和數(shù)據(jù)
create table user3 as select id,name from user1; -- 復(fù)制指定字段和數(shù)據(jù)
create table user4 as select id gid ,name gname from user1; -- 新表字段設(shè)置為新的名字
create table user5 as select id gid ,name gname from user1 where 1=2; -- 復(fù)制結(jié)構(gòu)不復(fù)制數(shù)據(jù)
-- 3.alter
-- 增加字段
ALTER TABLE "USER4" ADD ("tel" NUMBER(11) DEFAULT 13900001111 NOT NULL) ;
-- 刪除字段
ALTER TABLE "USER4" DROP("tel");
-- 更改表名
ALTER TABLE "USER5" RENAME TO "USER55";
-- 更改字段名
ALTER TABLE "USER4" RENAME COLUMN "tel" TO "randomkey";
-- 變更屬性
ALTER TABLE "USER4" MODIFY ("randomkey" VARCHAR2(11) DEFAULT 'sha256' );
-- 修改默認(rèn)值
ALTER TABLE "USER4" MODIFY ("GNAME" VARCHAR2(20),"randomkey" VARCHAR2(20));
網(wǎng)站欄目:【基礎(chǔ)操作】1.表操作
文章鏈接:
http://weahome.cn/article/gdogso.html