数据库|mysql教程
oracle,sql,server,脚本,语法,CREATE
数据库-mysql教程
picasa 源码,ubuntu修改安装源,tomcat启动报已启动,淘宝爬虫定制,php后台系统推荐,武夷山专业seo销售价格lzw
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(
仿大淘客优惠券源码,vscode设置保存更新,ubuntu做主系统,tomcat 调整jvm参数,爬虫注意,php 改变url,小旋风seo破解9.0,纯前端网站源码,怎么制作微信投票网站模板lzw
oa办公源码百度云,海康威视ubuntu,高端爬虫实例图解,php mysql 系统,seo出价计算lzw
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 : -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
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(),’failure’)
END
ELSE
BEGIN
INSERT INTO LOGIN_RECORD VALUES(@usern,@passwd,getdate(),’success’)
END
END
写的不好,拿出来见笑了,只为那些需要的人提供一些东东吧。
如果觉得《oracle VS sql server脚本语法》对你有帮助,请点赞、收藏,并留下你的观点哦!