Oracle vs SQL server script syntax

Source: Internet
Author: User
Oracle vs SQL server script syntax

Luo Weifeng 2010-7-9

The original Article is published in the QQ space.

 

 

In other words, du boss (which cannot be called now) will use Oracle and SQL Server to write scripts for ** respectively. This is terrible for me. A whole day, after the Oracle script is transplanted to sqlserver, I almost vomited to death. Now, it has been a long time and I feel that I will not be able to make any difference. I will post on my previous mental journey, so that more friends and sisters can take a detour.

 

This is the Oracle Syntax:

-- Author: luoweifeng
-- Time: 2010-6-23
Drop user Luo cascade;

Create user "Luo" Profile "default"
Identified by "oradb" default tablespace "users"
Account unlock;
Grant "Connect" to "Luo ";
Grant "resource" to "Luo ";

Connect Luo/oradb;

Create Table "Luo". "login_record "(
"User_name" varchar2 (10) Not null,
"User_passwd" varchar2 (10) Not null,
"Record_time" date default sysdate not null,
"Success" varchar2 (10) Not null
);

Create Table "Luo". "login "(
"User_name" varchar2 (10) Not null,
"User_passwd" varchar2 (10) Not null
);

 

Create or replace trigger "Luo". "login_record_triger"
Before insert on "Luo". "login" for each row
Begin
Insert into login_record values (
: New. user_name,
: New. user_passwd,
Sysdate,
'Hi'
);
End;

 

-- Create a stored procedure
Create or replace procedure login_procedure (
Usern in Luo. login. user_name % type, passwd in Luo. login. user_passwd % Type
)
Count_num integer;
Begin
Select count (*)
Into count_num
From Login
Where login. user_name = usern
And login. user_passwd = passwd;
If count_num = 0 then
Insert into "Luo". "login_record" values (usern, passwd, sysdate, 'failed ');
Dbms_output.put_line ('login faild! ');
Else
Insert into "Luo". "login_record" values (usern, passwd, sysdate, 'success ');
Dbms_output.put_line ('login success! ');
End if;
Commit;
Exception
When others then
Dbms_output.put_line ('exception occured! ');
Rollback;
End login_procedure;

/

 

The SQL Server syntax is as follows:

-- Recordloginwithtrigerusesql. SQL-creates the labtest Database
-- Author: Luo Weifeng
-- Time: 2010-6-23
-- All Rights Reserved.

-- Switch to the master database
Use master

-- Query whether there is a database named as the expected data name. If yes, delete it.
If exists (select * From sysdatabases where name = 'labtest ')
Begin
Raiserror ('dropping existing labtest database)
Drop database labtest
End
Go

-- Create a database (default value for size and so on)
Create Database labtest
Go

-- Create a table in the new database
Use labtest
Go

-- Check whether it is correct
If db_name () <> 'labtest'
Raiserror ('error in recordloginwithtrigerusesql. SQL, ''use labtest'' failed! Killing the spid now .'
, 22,127) with log
Go

-- Create a History Table
Create Table login_record (
"User_name" varchar (10) Not null,
"User_passwd" varchar (10) Not null,
"Record_time" date not null default (getdate ()),
"Success" varchar (10) Not null
)
Go

-- Create a user name/password table
Create Table "login "(
"User_name" varchar (10) Not null,
"User_passwd" varchar (10) Not null
)
Go

-- Check for errors
Raiserror ('Now at the create trigger section... ', 0, 1)
Go

-- Create a trigger

Create trigger login_record_triger
On Login
For insert
As
Begin
Declare @ new_name varchar (10 );
Declare @ new_passwd varchar (10 );
Set @ new_name = (select inserted. user_name from inserted)
Set @ new_passwd = (select inserted. user_passwd from inserted)
 
Insert into login_record values (
@ New_name,
@ New_passwd,
Getdate (),
'Hi'
);
End

Create procedure login_procedure
(
@ Usern varchar (10 ),
@ Passwd varchar (10)
)
As
Begin
Declare @ count_num integer;
Set @ count_num = (select count (*)
From Login
Where login. user_name = @ usern
And login. user_passwd = @ passwd)

 
If (@ count_num = 0)
Begin
Insert into login_record values (@ usern, @ passwd, getdate (), 'failed ')
End
Else
Begin
Insert into login_record values (@ usern, @ passwd, getdate (), 'success ')
End
End

 

It is not easy to write. I just give something to those who need it.

 

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.