oracle VS sql server脚本语法
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(
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 OR REPLACE PROCEDURE LOGIN_PROCEDURE(
usern IN LUO.LOGIN.USER_NAME%TYPE, passwd IN LUO.LOGIN.USER_PASSWD%TYPE
)AS
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,'failure');
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;
/
下面是sql server的语法:
--RecordLoginWithTrigerUseSql.SQL - Creates the LabTest database
--Author: Luo Weifeng
--Time : 2010-6-23
--All Rights Reserved.
--切换到master数据库
USE master
-- 查询有没有以我们期望的数据名为名的数据库,存在则删除
if exists (select * from sysdatabases where name='LabTest')
begin
raiserror('Dropping existing LabTest database ....',0,1)
DROP database LabTest
end
GO
-- 创建数据库(大小等用默认值)
CREATE DATABASE LabTest
GO
-- 进入新建数据库创建表
USE LabTest
GO
-- 检查是否正确
if db_name() 'LabTest'
raiserror('Error in RecordLoginWithTrigerUseSql.SQL, ''USE LabTest'' failed! Killing the SPID now.'
,22,127) with log
GO
--创建历史记录表
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 TABLE "LOGIN" (
"USER_NAME" VARCHAR(10) NOT NULL,
"USER_PASSWD" VARCHAR(10) NOT NULL
)
GO
-- 检查出错
raiserror('Now at the create trigger div ...',0,1)
GO
-- 创建触发器
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
(
@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(),'failure')
END
ELSE
BEGIN
INSERT INTO LOGIN_RECORD VALUES(@usern,@passwd,getdate(),'success')
END
END
写的不好,拿出来见笑了,只为那些需要的人提供一些东东吧。
推荐阅读
-
SQL SERVER常用语法汇总
-
SQL SERVER数据库的作业的脚本及存储过程
-
Oracle 实现类似SQL Server中自增字段的一个办法
-
SQL SERVER中各类触发器的完整语法及参数说明
-
sql server通过脚本进行数据库压缩全备份的方法【推荐】
-
Linux下通过python访问MySQL、Oracle、SQL Server数据库的方法
-
SQL Server、Oracle和MySQL判断NULL的方法
-
oracle层次查询,oracle 9i利用SQL演示脚本判断是叶子或根节点
-
sql server连接oracle并实现增删改查
-
EFCore 通过实体Model生成创建SQL Server数据库表脚本