## 简介
使用 pyhton 实现的功能简单的 DBMS 系统,主要功能如下:
- 初始化,产生默认 root 用户
- 用户登录功能(login)
- 使用数据库(use 命令)
- 创建用户、数据库、表(create 命令)
- 查询数据表中的数据(select 命令),支持简单 where 子句、order by,不支持聚集函数等
- 向数据表中插入数据(insert 命令),支持的数据类型有 int varchar double,支持简单的约束,不支持 where 子句
- 删除数据表中内容(delete 命令),支持简单的 where 子句
- 更新数据表中的内容(update 命令),支持简单的 where 子句
- 向用户授权功能(grant 命令)
- 收回权限功能(revoke 命令)
- help 命令
运行平台为:Windows,语言为 Python3,注意的是一定要有 F 盘,因为默认配置文件会建在 F 盘,您也可以修改 static_string.py 中 PATH_ROOT
## 缺陷
- 只能对数据库授权,而不能对数据表授权
- 一个表中只能支持一个约束条件
- 普通用户即使授予了对数据库的使用权限,也没法使用数据库(悲伤...),这里稍微一改可以实现
## 整体思路
![流程图](https://github.com/zzzskd/pictureandor/blob/master/Untitled%20Diagram.png)
## 使用命令
### 登录
```
login root root # 登录
```
### use
```
use sdust # 使用数据库
```
### create
```
create user zzz passwd 1 # 创建用户
create database sdust # 创建数据库
create table users(id int primary key, name varchar not null) # 创建数据表
create view users_view as select * from users # 创建视图
```
### insert
```
insert into users values(1, 'zzz') # 向表中插入数据
```
### delete
```
delete from users # 删除表中所有数据
delete from users where id = 1 # where 子句
```
### update
```
update users set name = 'zzz' # 更新表中所有数据
update users set id = 3 where name = 'yes' # where 子句
```
### select
```
select * from users
select id, name from users
select * from users order by id # order by 子句
select id, name from users_view # 在视图中查询
```
### grant
```
grant insert, select on test to zzz # 赋予用户权限
grant * on test, sdust to zzz
grant * on test, sdust to zzz, test
```
### revoke
```
revoke insert, select on test from zzz # 收回权限
revoke * on test, sdust from zzz
revoke * on test, sdust from zzz, test
```
### help
```
help database # 查看数据库信息
help table users # 查看数据表信息
help view users_view # 查看试图信息
```
### 退出
```
exit
```
### 存储用户文件结构
./config/users.json: { "user_name": {"password": "user_password", "type": 1} }
格式化:
```json
{
"user_name": {
"password": "user_password",
"type": 1
}
}
```
### 存储数据文件结构
./config/dictionary.json:
{"sdust": {"views": {"users_view": {"items": [{"nature": "id", "type": "int"}], "content": "select * from users"}}, "permissions": {"root": {"select": 1, "insert": 1, "update": 1, "delete": 1}}, "tables": {"users": {"size": 2, "items": [{"nature": "id", "limit": "primary key", "type": "int"}]}}}}
格式化:
```json
{
"sdust": {
"views": {
"users_view": {
"items": [
{
"nature": "id",
"type": "int"
}
],
"content": "select * from users"
}
},
"permissions": {
"root": {
"select": 1,
"insert": 1,
"update": 1,
"delete": 1
}
},
"tables": {
"users": {
"size": 2,
"items": [
{
"nature": "id",
"limit": "primary key",
"type": "int"
}
]
}
}
}
}
```
### 表的文件结构
./databasename/tablename.sql # 本质是个 .txt 文件
> 具体实现解解释见代码注释
没有合适的资源?快使用搜索试试~ 我知道了~
simple DBMS,数据库概论的课程设计.zip
共15个文件
py:13个
md:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 194 浏览量
2023-12-06
08:30:48
上传
评论
收藏 21KB ZIP 举报
温馨提示
数据库课程设计
资源推荐
资源详情
资源评论
收起资源包目录
simple DBMS,数据库概论的课程设计.zip (15个子文件)
001
README.md 5KB
DBMS_code
handle_revoke_functions.py 3KB
handle_grant_functions.py 3KB
handle_help.py 3KB
handle_delete_functions.py 5KB
handle.py 10KB
handle_select_functions.py 14KB
static_string.py 4KB
handle_update_functions.py 8KB
settings.py 526B
handle_create.py 8KB
README.md 5KB
handle_insert_functions.py 7KB
dbms.py 2KB
handle_where.py 0B
共 15 条
- 1
资源评论
LeapMay
- 粉丝: 2w+
- 资源: 2305
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功