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. ASP.NET-FineUI开发实践-5

    1.tree的右键事件和单击事件 页面就不写了,准备一个树和一个菜单控件,随便写点啥 JS:注意注释 var menuSettings = F('menuSettings'); var tree = ...

  2. div 固定宽高 水平垂直居中方法

    div固定宽高,水平垂直居中,根据所用单位不同,分成两种情况,分别是"px"和"%"情况. 例:将三层div做出三个边框,要求水平垂直居中.效果如图 情况一(单 ...

  3. 数据库、C#、Java生成唯一GUID 方法

    GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制值.GUID ...

  4. 把数据库中的null作为条件查询应该用is

    如select * from mbXX where tuijian is null 而不是select * from mbXX where tuijian=null

  5. 查询数据库返回List<Entity>问题

    如果判断所返回的List<Entity>是否为空不能用 list!=null,因为如果查询数据为空则会返回[],当与null判断的时候会判断为有数据,此时判断条件应该写成list.size ...

  6. iOS中使用图片作为颜色的背景图

    Objective-C: [UIColor colorWithPatternImage:[UIImage imageNamed:@"jpg"]]; Swift: UIColor(p ...

  7. C# LINQ 基本操作实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. sql查询语句心得

    1)where 有多个用in ,一个用= 2)自身链接 select A.Sno from S A,S B where A.Sname='a' AND A.City=B.City)) 3)外链接(同时 ...

  9. 命令passwd报错因inode节点处理记录

    命令passwd报错因inode节点处理记录故障现象:1.修改密码时报错 passwd: Authentication token manipulation error2.添加用户报错:unable ...

  10. nodejs学习记录

    一.环境搭建 1.安装express 局部安装 npm i express 全局安装 npm i -g express (命令行express无法使用) 环境变量 npm i -g express-g ...