oracle与sqlserver的区别?(详细一点)

oracle与sqlserver的区别?(详细一点)作用?开发方面的区别?

开发上边,至少有以下几点区别:

--sql server 与 oracle的区别:

  --DBMS 数据库管理系统

--1.数据类型不同。
--sql server 的数据类型:int ,smallint ,char,varchar,nchar,nvarchar,ntext,datetime,smalldatetime,money,decima,
--float,bit……

  --oracle 的数据类型:number(p,s),char,varchar2,Date,LOB
           --注意:insert into table_name values('1','张三','男',date'2012-3-5');---插入字符串日期前加date转换类型

--2.获得当前系统时间的函数不同。
--sql server :getdate()

  --oracle:sysdate
        --例如:设定日期格式的函数:to_char(sysdate,'yyy-mm-dd');

--3.在oracle中没有默认约束的说法
--sql server 中添加默认约束:alter table talbe_name add DF_table_name default('男') for sex;

  --oracle 中添加默认值:alter table table_name modify(sex default('男'));

--4.连接变量和字符串的方式不一样
--sql server 中连接:使用“+”连接,例如:print 'aaaa'+@name;

  --oracle  中连接:使用“||”连接,例如:dbms_output.put_line('aaa'||name);---name为变量

--5.oracle没有identity自动增长列,而是使用序列实现增长
--sql server 自动增长:在表的主键列中可直接使用identity(1,1)实现增长

  --oracle 使用序列自动增长:
                             create sequence se_id 
                             start with 1
                             increment by 1
  --使用序列实现自动增长:se_id.nextval

--6.条件语句if……else……的语法不同
--sql server中:
if 条件
begin
…………
end
else
begin
…………
end
--oracle中:
if 条件1 then
…………;
elsif 条件2 then
…………;
else
…………;
end if;

--7.case语句的语法不同
--sql server中:
--select ....case.....(else)....end....语句
select stuno '学号',case
when grade>=90 and grade<=100 then '★★★★'
when grade>=80 and grade when grade>=70 and grade when grade>=60 and grade<70 then '★'
else '差'
end as '等级' from score
go
--oracle中:
declare
nums number:=&nos;--&nos表示提示传入值
begin
case nums
when 100 then
dbms_output.put_line('满分也,不错');
when 90 then
dbms_output.put_line('90分页很不错了');
end case;
end;
--8.触发器创建语法不同
--sql server中:

     --首先判断触发器是否已经存在
     if exists (select * from sys.sysobjects where name='tr_delete')
--如果存在先删除
drop trigger tr_delete
     go

    --创建触发器
    create trigger tr_delete
    on bookInfo
    instead of delete
    as
        --定义变量
        declare @bookid int 
        select @bookid=Bookid from deleted---deleted执行删除语句( delete from BookInfo where BookId=1),自动生成的deleted表
        --删除与该图书的相关记录(先删除从表再删除主表)
        delete from borrowinfo where  bookid=@bookid
        delete from backinfo where  bookid=@bookid
        delete from BookInfo where BookId=@bookid
        --判断
        if @@error<>0
        begin
            print '删除失败'
            rollback transaction
        end
        else
        begin
            print '删除成功'
        end
    go
    delete from BookInfo where BookId=1        

 --oracle中:
    --创建触发器
    create or replace trigger tri_test
    before insert or update or delete 
    on table_name
    [for each row]---如果要使用 :new /:old 就必须使用行触发器
    declare
         nums varchar2(20);
    begin
      select 'F'||lpad('aa',5,0) into nums from dual;
    end;

--9.oracle中的存储过程
--sql server中存储过程:

        --判断存储过程是否已经存在
        if exists(select * from sys.sysobjects where name='proc_name')
 --如果存在先删除
 drop proc proc_name
        go

        --创建存储过程语句
        create proc/procedure proc_name
        @参数名1 数据类型 [out/output],
        @参数名2 数据类型 [out/output]
        as
              …………
        go

        --调用存储过程
        --如果有输出参数,则需定义变量(假设@参数2为输出参数)
        declare @变量名 数据类型
        exec proc_name @参数名1='aaa',@参数名2=@变量名 out


        ---oracle中带游标及循环的存储过程

         create or replace procedure proc_selCurrent
         (
                names varchar2
         )
         as
                cursor cursor_sel
                is
                select DepositSum,cardType,name,state from CurrentAccount where name like '%'||names||'%';
                dd number;
                cc number;
                nn varchar2(20);
                sta number;
                begin
                  open cursor_sel;
                       loop
                         fetch cursor_sel into dd,cc,nn,sta;
                         dbms_output.put_line('存款金额:'||dd||'姓名:'||nn);
                       exit when cursor_sel%notfound;
                       end loop;
                  close cursor_sel;
                end;

          --调用存储过程
          begin
            proc_selCurrent('a');
          end;

--10.创建用户的方式不同
--sql server中
--1、创建登陆账号:sa-----123456
create Login 登陆名称 with password='登陆密码'

       --修改登陆账户:
             alter Login 登陆名称 with name='新登录名称' and password='新登录密码'
       --禁用/启用登陆账号
             alter Login 登录名称 disable(禁用)/enable(启用)
       --删除登陆账号
             drop Login 登录名称

       --2、创建用户:
        create user 用户名 for/from Login 登陆名称

        --修改用户名
        alter user 用户名 with name='新用户名'

        --删除用户名
        drop user 用户名

        ---授权限
        grant select/update/delete/insert on 表名 to 用户名


    ---oracle中:

        ---创建用户语法:
              create user 用户名
              identified by 密码
              default tablespace users
              temporary tablespace temp
              quota 10M on users

              --修改密码:
              alter user 用户名 identified by 新密码

              --授予权限:
              grant create session to 用户名

              --删除用户
              drop user 用户名 cascade;

相比较而言,开发比较小规模的系统,适合采用SQL Server,它在Windows平台上配置维护都很简单。而开发比较大规模的系统,Oracle占优。至于技术上的差别,其实很小,而且一些比较老的文章中提到SQL Server所不支持的一些特性,其实在新版中早已支持。

oracle适合作为大型系统的数据库,sqlserver更适合中小型系统的数据库。另外,oracle可以在多种平台(linux、unix、windows)上面部署,sqlserver目前只支持windows。在开发工具方面,sql server management studio更加容易操作(跟windows、office一样的风格),plsql相比较没有那么强大,但是比纯命令行操作oracle要方便的多。

IPHONE和诺基亚的区别