专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > SQL

sqlserver与oracle的差异

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
sqlserver与oracle的区别

 sql server  oracle的区别:
--1.
数据类型不同。

--sql server 的数据类型:       int ,smallint ,char,varchar,nchar,nvarchar,ntext,datetime,smalldatetime,

money,decima,float,bit……
--oracle 的数据类型:number(p,s),char,varchar2,Date,LOB 

 

--触发器创建语法不同
      --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 @@error0
             begin
                 print '删除失败'
                 rollback transaction

              end
             else
             begin
                 print '[/size][size=10.5pt; font-family: 宋体;]删除成功'
             end
         go
         delete from BookInfo where BookId=1       
         
      --oracle[/size]中:
         --创建触发器
         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;

中存储过程:
            
             --[/size]判断存储过程是否已经存在
             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中带游标及循环的存储过程
[size=10.5pt; font-family: 宋体;" lang="EN-US]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('[/size][size=10.5pt; font-family: 宋体;]存款金额:'||dd||'[/size]姓名:'||nn);
                            exit when cursor_sel%notfound;
                            end loop;
                       close cursor_sel;
                     end;
                    
               --调用存储过程
               begin
                 proc_selCurrent('a');
               end;


    --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 用户名 c[size=13.5pt; font-family: 'Arial',sans-serif; color: #362e2b; background: white;" lang="EN-US]ascade;[/size]

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: