各個資料庫軟體對於sql的支援

2021-12-30 00:01:04 字數 4024 閱讀 3142

各個資料庫軟體對於sql的支援

最近正在學習資料庫這門課程,雖然sql有有統一的標準,但是各個資料庫軟體對於sql支援是不一樣的,上機遇到各種各樣的問題,就記錄在這個帖子上吧;

1,mysql是不支援對檢視建立觸發器的;

2,oracle只支援了級聯刪除on delete cascade卻不支援級聯更新on update cascade;

3,mysql中的條件控制語句比如if語句後是可以出現查詢語句selec的,但是oracle中是不可以的,只能實現begin開始前宣告變數,然後再begin語句後把查詢出來的的結果賦給變數,在oracle中條件控制語句是用when 的

4,mysql中新插入,修改後的行用new來表示,而刪除或者更新前的行用old來表示,而在oracle中則需要在nrow前面加上:號,還要在開頭加上一句referencing new as nrow;

但是在when後面的nrow是不用加上:號的;

下面是今天晚上的幾個例子(資料庫使用的是oracle):

[sql] 

create database student;  

create table students  

(sno varchar(15),  

sname varchar(20) not null,  

*** varchar(7),  

bdate date,  

height int,  

department varchar(20),  

primary key (sno));  

create table courses  

(cno varchar(8),  

cname varchar(20) not null,  

lhour int,  

credit int,  

semester varchar(6),  

primary key (cno));  

create table sc  

(sno varchar(15),  

cno varchar(8),  

grade smallint,  

primary key (sno,cno),  

foreign key (sno) references students(sno)  

on delete cascade,  

foreign key (cno) references courses(cno)  

on delete cascade);  

create or replace trigger upd_creadits after insert on sc  

referencing new as nrow for each row  

declare credits_count int;  

credits_number int;  

begin  

select count(*) into credits_count from credits where credits.sno=:nrow.sno;  

select credit into credits_number from courses where courses.cno=:nrow.cno;  

if :nrow.grade>=60 then  

if credits_count<>0 then  

update credits  

set sumcredit=sumcredit+credits_number  

where sno=:nrow.sno;  

else  

insert into credits values(:nrow.sno,credits_number,0);  

end if;  

else  

if credits_count<>0 then  

update credits   

set nopass=1+nopass  

where sno=:nrow.sno;  

else  

insert into credits values(:nrow.sno,0,1);  

end if;  

end if;  

end;  

/    

create or replace trigger upd_stuview instead of insert on student_grade

referencing new  as nrow for each row   

declare student_num int;  

course_num int;  

xuehao varchar(15);  

kechenghao varchar(8);  

begin   

begin  

select count(*) into student_num from students where students.sname=:nrow.sname;  

exception when no_data_found then  

dbms_output.put_line('不存在這個學生或者這門課程!');  

end;  

begin  

select count(*) into course_num from courses where courses.cname=:nrow.cname;  

exception when no_data_found then  

dbms_output.put_line('不存在這個學生或者這門課程!');  

end;  

select sno into xuehao from students where students.sname=:nrow.sname;  

select cno into kechenghao from courses where courses.cname=:nrow.cname;  

if  student_num<>0 and course_num<>0 then  

insert into sc values(xuehao,kechenghao,:nrow.grade);  

else dbms_output.put_line('不存在這個學生或者這門課程!');  

end if;  

end; 

下面是第乙個觸發器upa_creadits的mysql版本:  

delimiter |  

create trigger upd_creadits after insert on sc  

for each row  

begin  

if new.grade>=60 then  

if exists(select * from credits where credits.sno=new.sno) then  

update credits  

set sumcredit=sumcredit+(select credit from courses where courses.cno=new.cno)  

where sno=new.sno;  

else  

insert into credits values(new.sno,(select credit from courses where courses.cno=new.cno),0);  

end if;  

else  

if exists(select * from credits where credits.sno=new.sno) then  

update credits   

set nopass=1+nopass  

where sno=new.sno;  

else  

insert into credits values(new.sno,0,1);  

end if;  

end if;  

end| 

mysql不支援檢視觸發器;  

各個資料庫軟體對於sql的支援

最近正在學習資料庫這門課程,雖然sql有有統一的標準,但是各個資料庫軟體對於sql支援是不一樣的,上機遇到各種各樣的問題,就記錄在這個帖子上吧 1,mysql是不支援對檢視建立觸發器的 2,oracle只支援了級聯刪除on delete cascade卻不支援級聯更新on update cascad...

sql執行各個資料庫的儲存過程

對不同的資料庫進行同一操作 if exists select name from sysobjects where name up updatedatabase drop proc up updatedatabase gocreate proc up updatedatabase sql varch...

各個資料庫分頁

s ql server的分頁 select from select top pagesize from select top pagesize cureentpage from user table order by id asc as asystable order by id desc as b...