欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > 数据库第三次作业

数据库第三次作业

2024/10/24 6:31:20 来源:https://blog.csdn.net/m0_74082747/article/details/140266582  浏览:    关键词:数据库第三次作业

在数据库中创建一个表student用于存储学生信息
向student表中添加一条新记录
记录中id字段的值为1name字段的值为"monkey"grade字段的值为98.5
向student表中添加多条新记录
“bob”,95.5
“john”,90.0
“smith”,88.5
向student表中添加一条新记录,部分数据插入
“jone”
更新表,grade 大于90的加0.5
删除成绩为空的记录

mysql> create database stu;
mysql> create table student(
    -> id int primary key,
    -> name varchar(20) not null,
    -> grade float
    -> );
mysql> insert into  student values(1,'monkey',98.5);
mysql> insert into  student values(2,'bob',95.5),(3,'john',90.0),(4,'smith',88.5);
mysql> insert into student(id,name)values(5,'jone');
mysql> update student
    -> set grade=grade+0.5
    -> where grade>90;
mysql> delete from student
    -> where grade is null;
    
    mysql> select * from student;
+----+--------+-------+
| id | name   | grade |
+----+--------+-------+
|  1 | monkey |    99 |
|  2 | bob    |    96 |
|  3 | john   |    90 |
|  4 | smith  |  88.5 |
+----+--------+-------+

用户权限部分

创建一个用户test1使他只能本地登录拥有查询student表的权限
查询用户test1的权限
删除用户test1

mysql> create user test1@localhost identified by '20040830Nmx@';
  mysql> grant select on student.* to test1@localhost;
mysql> show grants for 'test1'@localhost;
+----------------------------------------------------+
| Grants for test1@localhost                         |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO `test1`@`localhost`          |
| GRANT SELECT ON `student`.* TO `test1`@`localhost` |
+----------------------------------------------------+
mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='test1';
mysql> FLUSH PRIVILEGES;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com