(8)oracle 表的增删改

表的命名

表需要字母开头

只能用如下字符 A-Z,a-z,0-9,$,#.

不能使用oracle保留字

长度不能超过30

 

 

创建一张表

create table 表名(字段名 数据类型,字段名 数据类型,......);

create table student(id number(3),name varchar2(10),birthday date);

 

添加字段

alter table 表名(字段名 数据类型);

alter table student add(score number(3));

 

修改字段长度

alter table 表名 modify(表名 字段名);

alter table student modify(score number(4));

 

修改字段名

alter table tableName rename column oldCName to newCName;

 

删除字段

alter table 表名 drop column 字段名;

alter table student drop column score;

 

删除表

drop table 表名;

drop table student;

 

修改表名

rename table 旧表名 to 新表名;

rename table student to class;

 

表中添加数据

insert into 表名 values(表数据,表数据,表数据);

insert into student values(1,'tom','10-5月-1990');

 

插入部分字段

insert into 表名(字段名,字段名)values(表数据,表数据);

insert into student(id,age)values(1,19);

查赋值null的字段(赋值null和什么都不添是有区别的)

select * from student where birthday is null;

非空

select * from student where birthday is not null;

 

修改字段

update 表名 set  字段名=aaa   where  另一字段=bbbb;

update student set  name='如来佛' where age=9999;

 

修改多字段

update student set name=‘如来佛’ ,id=1 where  age=9999;

 

删除表中数据

delete  from 表名;    

只删除表里的数据,可以恢复

在删除表中的数据之前设置一个回滚点 savepoint a;  (把这个回滚点设成a,名字可以随便起)

再需输入    rollback to a;  就能回到回滚点前的数据,可以有多个保存点。

 删除数据还可以用 truncate table 表名  这种删除方式不能找回数据,但删除速度快。

 

给字段加中文注释

COMMENT ON  COLUMN T_M2E_PUR_STOCK_IN.metering_code IS '检斤单号'

 

posted @ 2016-07-15 09:13  富坚老贼  阅读(208)  评论(0编辑  收藏  举报