zoukankan      html  css  js  c++  java
  • SQL语句(二十二)—— 权限授予和回收(作业练习)

    CREATE TABLE course (   
        Cno char(4)      NOT NULL, 
        Cname char(40)   DEFAULT NULL,   
        Cpno char(4)     DEFAULT NULL,   
        Ccredit smallint DEFAULT NULL,   
        PRIMARY KEY (Cno) 
    )
    
    --  
    -- 转存表中的数据 'course' 
    --  
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('1', '数据库', '5', 4);
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('2', '数学', NULL, 2);
    
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('3', '信息系统', '1', 4);  
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('4', '操作系统', '6', 3);  
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('5', '数据结构', '7', 4);  
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('6', '数据处理', NULL, 2);  
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('7', 'PASCAL语言', '6', 4);  
    
    INSERT INTO course (Cno, Cname, Cpno, Ccredit) 
    VALUES ('8', 'DB_DESIGN', '1', 2); 
    
    select * from course
    
    --  
    -- 表的结构 'student' 
    --  
    CREATE TABLE  student (   
        Sno char(9) NOT NULL,    
        Sname char(20) DEFAULT NULL ,   
        Ssex char(2) DEFAULT NULL,   
        Sage smallint DEFAULT NULL, 
        Sdept char(20) DEFAULT NULL,   
        PRIMARY KEY (Sno)
    )
    
    --  
    -- 转存表中的数据 'student' 
    --  
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('151332087', 'Douzi', '', 20, 'CS');  
    
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('200215121', '李勇', '', 20, 'CS');  
    
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('200215122', '刘晨', '', 19, 'CS');  
    
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('200215123', '王敏', '', 18, 'MA');  
    
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('200215125', '张立', '', 19, 'IS');  
    
    INSERT INTO student (Sno, Sname, Ssex, Sage, Sdept) VALUES ('200215128', '陈冬', '', 18, 'IS'); 
    
    select * from student
    
    --  
    -- 表的结构 'sc' 
    --   
    CREATE TABLE sc ( 
        Sno char(9) NOT NULL DEFAULT '',   
        Cno char(4) NOT NULL DEFAULT '',   
        Grade smallint DEFAULT NULL,   
        PRIMARY KEY (Sno,Cno)
    ) 
    
    --  
    -- 转存表中的数据 'sc' 
    --  
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('151332087', '1', 99);  
    
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('200215121', '1', 92);  
    
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('200215121', '2', 85); 
     
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('200215121', '3', 88);  
    
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('200215122', '2', 90);  
    
    INSERT INTO sc (Sno, Cno, Grade) 
    VALUES ('200215122', '3', 80); 
    
    select * from SC
    
    --修改表属性
    Alter Table Course
    Add Constraint course_ibfk_1 Foreign key(Cpno) References Course(Cno);
    
    Alter Table sc
    Add Constraint sc_ibfk_1 Foreign key(Sno) References student(Sno);
    
    Alter Table sc
    Add Constraint sc_ibfk_2 Foreign key(Cno) References course(Cno);
    
    --p143, 表4.4
    create login Dou1 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u1 for login Dou1 with default_schema = abo
    
    create login Dou3 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u2 for login Dou3 with default_schema = abo
    
    
    create login Dou4 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u3 for login Dou4 with default_schema = abo
    
    
    create login Dou5 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u4 for login Dou5 with default_schema = abo
    
    
    create login Dou6 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u5 for login Dou6 with default_schema = abo
    
    
    create login Dou7 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u6 for login Dou7 with default_schema = abo
    
    
    create login Dou8 with password = '1234', default_database = Prac
    
    --创建数据库用户(为上一条指令中 Prac 数据库创建用户)
    create user u7 for login Dou8 with default_schema = abo
    
    --当u1 赋予对表Student的查询权限
    Grant Select 
    On Student
    To u1
    
    --当u2 赋予对表student的全部权限
    Grant All privileges
    On Student
    To u2
    
    Grant Update(Sno)
    On Student
    To U4
    
    Grant Insert
    On SC
    To U5
    with Grant option
    
    Setuser 'U5'
    Grant Insert
    On SC
    To U6
    
    exec sp_helprotect
    
    
    --收回权限
    Revoke Select
    On Student
    From U1
    
    Revoke All privileges
    On Student
    From u2
    
    --查询权限
    exec sp_helprotect
  • 相关阅读:
    python——math模块实现向上、向下取整
    Python 实现定时任务
    Python 删除某一目录下的所有文件或文件夹
    linux -bash: netstat: command not found及下载报错解决方法
    CentOS password无法输入问题
    差分信号(Differential Signal)
    成功做事的要点
    记我参加过的竞赛——“飞思卡尔杯”全国大学生智能汽车竞赛
    C ~ 一个串口接收思路
    C ~ char int 等数据转换问题
  • 原文地址:https://www.cnblogs.com/douzujun/p/6886051.html
Copyright © 2011-2022 走看看