create user test identified by test
default tablespace users
temporary tablespace temp
quota 3M on users; grant connect,resource to test with admin option; conn test/test show user;
alter user test identified by test1;//修改用户口令 grant create any view to scott;
revoke create any view from scott; grant select,update on dept to public;//授予实体权限
revoke update on dept from public; //回收实体权限 create role app_user identified by hello; //创建角色
grant create view to app_user; //授予创建视图权限
grant app_user to test; //角色授予用户,这些用户都具有这个角色的权限 create user WangMing identified by WangMing
default tablespace userwang
temporary tablespace tempwang
quota 3M on userwang; create user LiYong identified by LiYong
default tablespace userli
temporary tablespace templi
quota 3M on userli;
CREATE USER WangMing IDENTIFIED BY WangMing
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA 3M ON users; CREATE USER LIYONG IDENTIFIED BY LIYONG
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA 3M ON users; GRANT CONNECT,RESOURCE to WangMing WITH ADMIN OPTION;
GRANT CONNECT,RESOURCE to LIYONG WITH ADMIN OPTION; CREATE TABLE Mydept
(
DNO VARCHAR2(10),
DNAME VARCHAR2(10),
MANAGER VARCHAR2(10),
LOC VARCHAR2(10),
PHONE VARCHAR(10),
CONSTRAINT PK_Mydept PRIMARY KEY (DNO)
); CREATE TABLE Myemp
(
ENO VARCHAR2(10),
ENAME VARCHAR2(10),
AGE NUMBER(10),
JOB VARCHAR2(10),
SAL NUMBER(10),
DNO VARCHAR2(10),
CONSTRAINT PK_Myemp PRIMARY KEY (ENO),
CONSTRAINT FK_Myemp_To_Mydept FOREIGN KEY (DNO) REFERENCES Mydept (DNO)
);
INSERT INTO Mydept VALUES('','SALES','ZHAOSI','WuHan','');
INSERT INTO Myemp VALUES('','LIYONG',26,'SALESMAN',3400,'');
INSERT INTO Myemp VALUES('','SCOTT',24,'SALESMAN',3400,'');
INSERT INTO Myemp VALUES('','WANGMING',24,'SALESMAN',3400,''); INSERT INTO scott.Mydept VALUES('','OFFICE','ZHANGHENG','BeiJing',''); GRANT select(MAX(SAL)) ON Myemp TO ZHANGXIN;
CREATE TABLE Employee
(
ENO VARCHAR2(10),
ENAME VARCHAR2(10),
BIRTH VARCHAR(15),
JOB VARCHAR2(10),
SAL VARCHAR2(10),
DNO VARCHAR2(10),
STATE VARCHAR2(10),
PRIMARY KEY(ENO),
FOREIGN KEY(DNO) REFERENCE TO Department(DNO)
);
CREATE TABLE Department
(
DNO VARCHAR2(10),
DNAME VARCHAR2(10),
MAGNO VARCHAAR2(10),
LOC VARCHAR2(10),
PHONE VARCHAR2(12),
PRIMARY KEY(DNO)
); CREATE TABLE Teacher
(
Eno NUMERIC(4),
Sal NUMERIC(7,2),
PJob char(10),
CONSTRAINT PK_Teacher PRIMARY KEY(Eno) VALIDATE
); CREATE OR REPLACE TRIGGER Insert_Or_Update_Sal
BEFORE INSERT OR UPDATE ON Teacher
FOR EACH ROW
WHEN((NEW.PJob='教授') AND (new.Sal<4000))
BEGIN
select 4000 into:new.Sal from dual;
END;
/ INSERT INTO Teacher VALUES('','','教授');
INSERT INTO Teacher VALUES('','','教授');
INSERT INTO Teacher VALUES('','','教授'); CREATE TABLE Sal_log
(
Eno NUMERIC(4),
Sal NUMERIC(7,2),
Username char(80),
DDate TIMESTAMP,
CONSTRAINT PK_Sal_log PRIMARY KEY(Eno)
); CREATE OR REPLACE TRIGGER Insert_Sal
AFTER INSERT ON Teacher
FOR EACH ROW
BEGIN
INSERT INTO Sal_log VALUES(:new.Eno,:new.Sal,user,sysdate);
END;
/ CREATE TABLE Department
(
No NUMBER(12),
Name CHAR(40),
PRIMARY KEY(No)
); CREATE TABLE Students
(
No NUMBER(12),
Name CHAR(8),
Sex INTEGER DEFAULT 0,
Birthday DATE,
Class CHAR(40),
DeptNo NUMBER(12),
PRIMARY KEY(No),
FOREIGN KEY(DeptNo) REFERENCES Department(No)
); CREATE TABLE Course
(
No NUMBER(12),
Name CHAR(8),
Credit FLOAT,
PRIMARY KEY(No)
); CREATE TABLE SC
(
CNo NUMBER(12),
SNo NUMBER(12),
Grade FLOAT,
PRIMARY KEY(CNo,SNo),
FOREIGN KEY(CNo) REFERENCES Course(No),
FOREIGN KEY(SNo) REFERENCES Students(No)
); CREATE TABLE SC_U
(
CNo NUMBER(12),
SNo NUMBER(12),
Oldgrade FLOAT,
Newgrade FLOAT
); CREATE OR REPLACE TRIGGER SC_T
AFTER UPDATE OF Grade ON SC
FOR EACH ROW
WHEN (NEW.Grade>=1.1*OLD.Grade)
BEGIN
INSERT INTO SC_U(SNo,CNo,OldGrade,NewGrade)
VALUES(:OLD.SNo, :OLD.CNo, :OLD.Grade, :NEW.Grade);
END;
/ CREATE TABLE StudentInsertLog
(
InsertDate DATE,
InsertNumber NUMBER(12),
Operator CHAR(20)
); CREATE OR REPLACE TRIGGER Student_Count
AFTER INSERT ON Students
DECLARE
ICount NUMBER(12);
temp NUMBER(12);
BEGIN
SELECT COUNT(*) INTO temp FROM StudentInsertLog;
SELECT COUNT(*) INTO ICount FROM Students;
IF(temp<>0) THEN
SELECT InsertNumber INTO temp FROM StudentInsertLog
WHERE InsertDate = (SELECT MAX(InsertDate) FROM StudentInsertLog);
END IF;
INSERT INTO StudentInsertLog (InsertDate, InsertNumber, Operator)
VALUES(SYSDATE, ICount-temp,user);
END;
/

sql语句相关操作的更多相关文章

  1. [20190328]简单探究sql语句相关mutexes.txt

    [20190328]简单探究sql语句相关mutexes.txt --//摘要:http://www.askmaclean.com/archives/understanding-oracle-mute ...

  2. [20190329]探究sql语句相关mutexes补充2.txt

    [20190329]探究sql语句相关mutexes补充2.txt --//昨天测试sql语句相关mutexes,看看如果出现多个子光标的情况. 1.环境:SCOTT@book> @ ver1P ...

  3. 捷信达会员管理系统SQL语句相关

    捷信达会员管理系统SQL语句相关 USE gshis GO SET ANSI_NULLS, QUOTED_IDENTIFIER ON GO /***************************** ...

  4. MySQL与SQL语句的操作

    MySQL与SQL语句的操作 Mysql比较轻量化,企业用的是Oracle,基本的是熟悉对数据库,数据表,字段,记录的更新与修改 1. mysql基本信息 特殊数据库:information_sche ...

  5. SQL语句 远程操作数据库

    --远程操作数据库SQL语句exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '211.81.251.85 'exec sp_addlinkedsr ...

  6. EF Core中执行Sql语句查询操作之FromSql,ExecuteSqlCommand,SqlQuery

    一.目前EF Core的版本为V2.1 相比较EF Core v1.0 目前已经增加了不少功能. EF Core除了常用的增删改模型操作,Sql语句在不少项目中是不能避免的. 在EF Core中上下文 ...

  7. 使用Phoenix通过sql语句更新操作hbase数据

    hbase 提供很方便的shell脚本,可以对数据表进行 CURD 操作,但是毕竟是有一定的学习成本的,基本上对于开发来讲,sql 语句都是看家本领,那么,有没有一种方法可以把 sql 语句转换成 h ...

  8. 使用Mysql执行SQL语句基础操作

    SQL:  又叫结构化语言,是一种用来操作RDBMS的数据库语言,在关系型数据库中都支持使用SQL语句,如oracle.mysql等等. 注意: 在关系型数据库中sql语句是通用的,而在非关系型数据库 ...

  9. java通过反射拿到mybatis中的sql语句并操作

    private static final int MaxBatchLength = 100; public void updateBatch(List<T>list, BaseMapper ...

随机推荐

  1. [Angular 2] Rendering an Observable Date with the Async and Date Pipes

    Instead of simply pushing numbers on a timer into the template, now we'll move on to pushing actual ...

  2. STL之set && multiset

    一.set 在了解关联容器set之前,让我们先来看看下面这个例子,并猜测该例子输出什么: // stl/set1.cpp #include <iostream> #include < ...

  3. 【移动开发】Android中WIFI开发总结(二)

    搞了好几天终于有点眉目了,这里接着总结一下Android中WiFi的使用,在前面(http://smallwoniu.blog.51cto.com/3911954/1334951)我们已经简单了解了W ...

  4. JAVA - Comparable接口 与 Comparator接口

      Similarities:Both are custom ways to compare two objects.Both return an int describing the relatio ...

  5. 【转】app瘦身

    iPhone经过这几年的发展,已经发生了很大的变化,例如屏幕变得更加多样,尺寸更多,内存变得更大,CPU的架构也在变化.伴随着iPhone的变化,iOS也在变化,例如AutoLayout.size c ...

  6. NOI2015 程序自动分析

    /* 十分简单的题面 离散化一下 然后并茶几一下就OK了 跑的死慢 可能还有更优的方法吧 */ #include<iostream> #include<cstdio> #inc ...

  7. 数据库连接超时和go away、如何检测数据库的最大连接数

    搜索连接bi库超时 数据库连接超时 go away go away和连接超时之间的关系是什么? 写一个例子测试一下. 如何检测数据库的最大连接数

  8. 使用VS2012的C++生成dll

    1,首先,通过File->New Project的方式新建一个工程,打开"New Project"对话框. 2,选择Visual C++语言下的 Win32->Win3 ...

  9. .NET Reflector 8.3.3.115 官方最新版+注册机(强大的.NET反编译工具破解版)

    Lutz Roeder’s .NET Reflector,是一个可以将以.NET Framework为基础开发出来的的DLL或EXE文件,反编译为原始程序的工具软件..NET Reflector 工具 ...

  10. 沙盒操作的核心函数 - NSSearchPathForDirectoriesInDomains用法

    1. iPhone会为每一个应用程序生成一个私有目录,这个目录位于: /Users/sundfsun2009/Library/Application Support/iPhone Simulator/ ...