-- 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.表操作
链接分享:
http://cdxtjz.com/article/gdogso.html