一些惯用的sql语句

一些常用的sql语句
添加一列
alter table 表名 add 列名 类型;
添加一行
insert into 表名 values ('','','');


删除一行
delete from 表名 where 条件;
删除一列
ALTER TABLE 表名 DROP COLUMN 列名;



修改字段的值
update 表名 set 字段='xxxx' where 字段='yyy'

根据一张表创建另一张表(也可以在原表上加一定的条件)
select * into a_s_unit from  s_unit weher id in(1,2,3,4) ;



使用rename关键字来实现字段名的修改:alter table 表名 rename column旧的字段名 to 新的字段名名;
使用modify关键字来实现对数据类型的修改:alter table 表名 modify 字段名 数据类型;


oralce 修改有数据的列的类型

1,建立临时列
alter table S_UNIT_INCOME add income_fee_bak decimal(18,6);

2.把修改的列的数据导入到临时列
update s_unit_income set income_fee_bak=income_fee;

3.把列的数据全部修改为空
update s_unit_income set income_fee='';

4.修改列的类型
alter table S_UNIT_INCOME modify income_fee decimal(18,6);

5.把临时列的数据导入到修改的列
update s_unit_income set income_fee=income_fee_bak;

6.删除临时列
alter table S_UNIT_INCOME drop column income_fee_bak;








增加主键约束
alter table S_PROJECT add constraint PK__S_PROJECT primary key(ID);

oracle修改数据库密码
alter user 数据库名 identified by 密码;