【基礎操作】1.表操作
阿新 • • 發佈:2018-03-30
create table number alter -- 1.基本表操作表
drop table user1;
create table user1(
id number(5,3) not null, -- (N,M) N:一共幾位,M:小數後幾位
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.創建表
create table user2 as select * from user1; -- 復制全部字段和數據
create table user3 as select id,name from user1; -- 復制指定字段和數據
create table user4 as select id gid ,name gname from user1; -- 新表字段設置為新的名字
create table user5 as select id gid ,name gname from user1 where 1=2; -- 復制結構不復制數據
-- 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' );
-- 修改默認值
ALTER TABLE "USER4" MODIFY ("GNAME" VARCHAR2(20),"randomkey" VARCHAR2(20));
【基礎操作】1.表操作