SQL Window - oracle 与 MySQl的学习笔记(一)

来源:互联网 发布:如何隐藏域名注册信息 编辑:程序博客网 时间:2024/05/17 02:46

-----------------------------alter的使用
 --oracle
create table zpf(id number,name varchar(12),sex char(2)  default  'W');
 --mysql
create table zpf(id numeric,name varchar(12),sex enum("M","W")  default  'W');

---oracle增加列
alter table zpf add (id2 varchar2(2));
alter table zpf add id2 varchar2(2);

 --mysql
  alter table zpf add ( id2 int);
  alter table zpf add  id3 int;
--oracle 删除列
alter table zpf drop column  id2;
  --mysql
  alter table zpf drop column  id2;
  alter table zpf drop  id2;
--oracle 修改列的类型
  alter table zpf modify(id varchar2(2)); 
  alter table zpf modify id varchar(2)
  --mysql
  alter table zpf modify id varchar(2); 
  alter table zpf change id id tinyint;
--oracle 重命名 表
 alter table zpf2 rename to zpf;
 --mysql
 alter table zpf rename to zpf2;
 alter table zpf rename zpf2;
--oracle  重命名 列
 alter table zpf rename column id2 to id3;
 --mysql
   alter table zpf change id id4 int;
---oracle删除表
drop table  zpf;
  --mysql
  drop table  zpf;
  drop table if exists zpf;
-------------------------------insert 的使用
select *  from zpf;
  ---制定字段插入
insert into zpf(id,name)values(1,'zhangpf');
insert into zpf(id,name,sex)values(1,'zhangpf','M');
  --默认全部插入
insert into zpf values(1,'zhangpf','M');
  --mysql特殊
  insert into zpf(id,name)values(1,'zhangpf'),(2,'liqiqi');--可以同时插入多条数据
  insert into zpf set name='hjt';
  --引用先前设置的值
   --准备数据
      --oracle
      alter table zpf add age number;
      alter table zpf rename column id2 to age2;
      update zpf set age=2 where sex='W';
      update zpf set age=3 where sex<>'W';
      --mysql
      alter table zpf add age int;
      alter table zpf change id2  age2 int;
      update zpf set age=2 where sex='W';
      update zpf set age=3 where sex<>'W';
   --mysql
      insert into zpf(id,age2)values(3,id*3); --允许 
      insert into zpf(id,age2)values(age2*3,3); --不允许,得不到想要的结果,前面字段插入空值 
   --oracle不支持这个方式的插入
 --子查询插入数据insert into 。。。。select 。。。
   --oracle
       create table zpf2 as select * from zpf where 1=2;
       select * from zpf2;
      
       insert into zpf2 select * from zpf;
       insert into zpf2(id,name) select  id,name from zpf where sex='W';
   --mysql
       create table zpf2 as select * from zpf where 1=2;
       create table zpf2  select * from zpf where 1=2; --建表时mysql的AS关键字可有可无
       
       insert into zpf2 select * from zpf;
       insert into zpf2(id,name) select  id,name from zpf where sex='W';
-------------------load的使用
       create table zpf3 as select * from zpf where 1=2;
   --mysql
       --在设置了唯一键的情况下
       load data local infile 'C:/ini.txt'  into table zpf3 fields terminated by ',' enclosed by '' lines terminated by '\n'; --不考虑键值,仅是添加
       load data local infile 'C:/ini.txt' replace into table zpf3 fields terminated by ',' enclosed by '' lines terminated by '\n';--唯一键相同情况下,更新此键数据
       load data local infile 'C:/ini.txt' ignore into table zpf3 fields terminated by ',' enclosed by '' lines terminated by '\n';--唯一键相同情况下,不更新此键数据
       --未设置唯一键时,效果都一样
   --oracle 不再叙述 (sqlload的使用) 

原创粉丝点击