SQL support for various database software

Source: Internet
Author: User

Various database software for SQL support recently is learning the database course, although SQL has a unified standard, but each database software for SQL support is different, machine encountered a variety of problems, record it on this post. 1. mysql does not support creating triggers for views. 2, oracle only supports cascade deletion on delete cascade, but does not support cascade update on update cascade. 3. The query statement selec can appear after the conditional control statement such as IF statement in mysql, but it is not possible in oracle. It can only declare variables before begin starts, and then assign the query results to the variables after the begin statement is executed, in oracle, the condition control statement is 4 in when, mysql is newly inserted, the modified row is represented by new, and the row before deletion or update is represented by old, in oracle, you need to add the number before nrow, and add a referencing new as nrow at the beginning; but n after the when Row does not need to be added: Number; below are several examples of this evening (the database uses oracle): [SQL] Create database student; create table Students (SNO varchar (15 ), SNAME varchar (20) not null, SEX 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;/create or replace trigger Upd_StuView instead of insert on partition new as nrow for each row declare student_num int; course_num int; xuehao varchar (15 ); kechenghao varchar (8); begin select count (*) into student_num from Students where Students. sname =: nrow. sname; exception when no_data_found then dbms_output.put_line ('This student does not exist or this course! '); End; begin select count (*) into course_num from courses where courses. cname =: nrow. cname; exception when no_data_found then dbms_output.put_line (' This student does not exist or this course! '); 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 ('This student does not exist or this course! '); End if; end; below is the mysql version of the first trigger upa_creadits: 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,); end if; end | mysql does not support view triggers;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.