日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Bootstrap4+MySQL前后端综合实训-Day04-PM【PowerDesigner 图形化数据库设计软件(设置依赖关系、自动增长主键、生成sql语句)、SQLyog软件(备份数据库)】

發布時間:2024/9/30 数据库 32 豆豆

【Bootstrap4前端框架+MySQL數據庫】前后端綜合實訓【10天課程 博客匯總表 詳細筆記】

目 ? 錄

PowerDesigner軟件

5張數據表之間的依賴關系圖

設置數據表的自動增長主鍵

設置timestrap默認值——點擊standard checks,在選項卡里設置default值。

設置數據表之間的關系——Reference

創建5張數據表并生成(數據庫腳本)sql語句

SQLyog數據庫管理軟件

修改SQL語句+成功執行(0 errors、0 warnings)

備份數據庫的數據

備份數據導出的sql文件

數據表text字段

數據表主鍵說明

多表連接查詢


PowerDesigner軟件

大佬博客:PowerDesigner個人使用總結

5張數據表之間的依賴關系圖

多對多關系 --> 拆分數據表

不同的用戶可以操作不同的欄目,多對多-->拆分數據表-->兩個“一對多”

logs_info:logs_content——記錄操作內容(增刪改加、登錄信息)。

設置數據表的自動增長主鍵

設置timestrap默認值——點擊standard checks,在選項卡里設置default值。

設置數據表之間的關系——Reference

創建5張數據表并生成(數據庫腳本)sql語句

  • 操作步驟:Database -> Generate?Database

/*==============================================================*/ /* DBMS name: MySQL 5.0 */ /* Created on: 2020/11/19 15:03:44 */ /*==============================================================*/drop table if exists item_user;drop table if exists logs_info;drop table if exists news_info;drop table if exists news_item;drop table if exists user_info;/*==============================================================*/ /* Table: item_user */ /*==============================================================*/ create table item_user (item_user_id int not null,user_id int,item_id int,primary key (item_user_id) );/*==============================================================*/ /* Table: logs_info */ /*==============================================================*/ create table logs_info (logs_id int not null,user_id int,logs_content char(10),primary key (logs_id) );/*==============================================================*/ /* Table: news_info */ /*==============================================================*/ create table news_info (news_id int not null auto_increment comment '新聞主鍵',item_id int not null,news_title varchar(255) comment '新聞標題',news_image varchar(255) comment '新聞圖片',news_content text comment '新聞內容',create_time datetime comment '創建時間',update_time timestamp comment '更新時間',primary key (news_id) );alter table news_info comment '新聞信息表';/*==============================================================*/ /* Table: news_item */ /*==============================================================*/ create table news_item (item_id int not null auto_increment comment '新聞欄目id',item_name varchar(255) not null comment '新聞名稱',create_time datetime not null comment '創建時間',update_time timestamp not null default CURRENT_TIMESTAMP comment '修改時間',primary key (item_id) );alter table news_item comment '新聞欄目表';/*==============================================================*/ /* Table: user_info */ /*==============================================================*/ create table user_info (user_id int not null auto_increment comment '用戶主鍵ID',user_name varchar(255) not null comment '用戶名',user_pwd varchar(255) binary not null comment '用戶密碼',create_time datetime comment '創建時間',update_time timestamp(0) comment '更改時間',primary key (user_id) );alter table user_info comment '用戶信息表';alter table item_user add constraint FK_Reference_2 foreign key (user_id)references user_info (user_id) on delete restrict on update restrict;alter table item_user add constraint FK_Reference_3 foreign key (item_id)references news_item (item_id) on delete restrict on update restrict;alter table logs_info add constraint FK_Reference_1 foreign key (user_id)references user_info (user_id) on delete restrict on update restrict;alter table news_info add constraint FK_Reference_4 foreign key (item_id)references news_item (item_id) on delete restrict on update restrict;

SQLyog數據庫管理軟件

修改SQL語句+成功執行(0 errors、0 warnings)

/*==============================================================*/ /* Table: item_user */ /*==============================================================*/ CREATE TABLE item_user (item_user_id INT NOT NULL COMMENT '用戶欄目關系主鍵',user_id INT COMMENT '用戶主鍵ID',item_id INT COMMENT '欄目ID',create_time DATETIME COMMENT '創建時間',update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (item_user_id) );ALTER TABLE item_user COMMENT '欄目與用戶之間的關系表';/*==============================================================*/ /* Table: logs_info */ /*==============================================================*/ CREATE TABLE logs_info (logs_id INT NOT NULL,user_id INT,logs_content CHAR(10),create_time DATETIME COMMENT '創建時間',update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (logs_id) );/*==============================================================*/ /* Table: news_info */ /*==============================================================*/ CREATE TABLE news_info (news_id INT NOT NULL AUTO_INCREMENT COMMENT '新聞主鍵',item_id INT NOT NULL,news_title VARCHAR(255) COMMENT '新聞標題',news_image VARCHAR(255) COMMENT '新聞圖片',news_content TEXT COMMENT '新聞內容',create_time DATETIME COMMENT '創建時間',update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (news_id) );ALTER TABLE news_info COMMENT '新聞詳情信息表';/*==============================================================*/ /* Table: news_item */ /*==============================================================*/ CREATE TABLE news_item (item_id INT NOT NULL AUTO_INCREMENT COMMENT '新聞欄目id',item_name VARCHAR(255) NOT NULL COMMENT '欄目名稱',create_time DATETIME COMMENT '創建時間',update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (item_id) );ALTER TABLE news_item COMMENT '新聞欄目表';/*==============================================================*/ /* Table: user_info */ /*==============================================================*/ CREATE TABLE user_info (user_id INT AUTO_INCREMENT COMMENT '用戶主鍵ID',user_name VARCHAR(255) NOT NULL COMMENT '用戶名',user_pwd VARCHAR(255) BINARY NOT NULL COMMENT '用戶密碼',create_time DATETIME COMMENT '創建時間',update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (user_id) );ALTER TABLE user_info COMMENT '用戶信息表';ALTER TABLE item_user ADD CONSTRAINT FK_Reference_2 FOREIGN KEY (user_id)REFERENCES user_info (user_id) ON DELETE RESTRICT ON UPDATE RESTRICT;ALTER TABLE item_user ADD CONSTRAINT FK_Reference_3 FOREIGN KEY (item_id)REFERENCES news_item (item_id) ON DELETE RESTRICT ON UPDATE RESTRICT;ALTER TABLE logs_info ADD CONSTRAINT FK_Reference_1 FOREIGN KEY (user_id)REFERENCES user_info (user_id) ON DELETE RESTRICT ON UPDATE RESTRICT;ALTER TABLE news_info ADD CONSTRAINT FK_Reference_4 FOREIGN KEY (item_id)REFERENCES news_item (item_id) ON DELETE RESTRICT ON UPDATE RESTRICT;

不用管理創建時間和修改時間:

  • create_time ? ? ? ? ? datetime?not?null?DEFAULT?CURRENT_TIMESTAMP,
  • update_time??????????timestamp?not?null?DEFAULT?CURRENT_TIMESTAMP?ON?UPDATE?CURRENT_TIMESTAMP,

備份數據庫的數據

? ?

備份數據導出的sql文件

/* SQLyog Ultimate v11.22 (64 bit) MySQL - 5.5.56 : Database - news_manager ********************************************************************* *//*!40101 SET NAMES utf8 */;/*!40101 SET SQL_MODE=''*/;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/`news_manager` /*!40100 DEFAULT CHARACTER SET utf8 */;USE `news_manager`;/*Table structure for table `item_user` */DROP TABLE IF EXISTS `item_user`;CREATE TABLE `item_user` (`item_user_id` int(11) NOT NULL COMMENT '用戶欄目關系主鍵',`user_id` int(11) DEFAULT NULL COMMENT '用戶主鍵ID',`item_id` int(11) DEFAULT NULL COMMENT '欄目ID',`create_time` datetime DEFAULT NULL COMMENT '創建時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`item_user_id`),KEY `FK_Reference_2` (`user_id`),KEY `FK_Reference_3` (`item_id`),CONSTRAINT `FK_Reference_3` FOREIGN KEY (`item_id`) REFERENCES `news_item` (`item_id`),CONSTRAINT `FK_Reference_2` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='欄目與用戶之間的關系表';/*Data for the table `item_user` *//*Table structure for table `logs_info` */DROP TABLE IF EXISTS `logs_info`;CREATE TABLE `logs_info` (`logs_id` int(11) NOT NULL,`user_id` int(11) DEFAULT NULL,`logs_content` char(10) DEFAULT NULL,`create_time` datetime DEFAULT NULL COMMENT '創建時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`logs_id`),KEY `FK_Reference_1` (`user_id`),CONSTRAINT `FK_Reference_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;/*Data for the table `logs_info` *//*Table structure for table `news_info` */DROP TABLE IF EXISTS `news_info`;CREATE TABLE `news_info` (`news_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '新聞主鍵',`item_id` int(11) NOT NULL,`news_title` varchar(255) DEFAULT NULL COMMENT '新聞標題',`news_image` varchar(255) DEFAULT NULL COMMENT '新聞圖片',`news_content` text COMMENT '新聞內容',`create_time` datetime DEFAULT NULL COMMENT '創建時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`news_id`),KEY `FK_Reference_4` (`item_id`),CONSTRAINT `FK_Reference_4` FOREIGN KEY (`item_id`) REFERENCES `news_item` (`item_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='新聞詳情信息表';/*Data for the table `news_info` *//*Table structure for table `news_item` */DROP TABLE IF EXISTS `news_item`;CREATE TABLE `news_item` (`item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '新聞欄目id',`item_name` varchar(255) NOT NULL COMMENT '欄目名稱',`create_time` datetime DEFAULT NULL COMMENT '創建時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`item_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='新聞欄目表';/*Data for the table `news_item` *//*Table structure for table `user_info` */DROP TABLE IF EXISTS `user_info`;CREATE TABLE `user_info` (`user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用戶主鍵ID',`user_name` varchar(255) NOT NULL COMMENT '用戶名',`user_pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '用戶密碼',`create_time` datetime DEFAULT NULL COMMENT '創建時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`user_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='用戶信息表';/*Data for the table `user_info` */insert into `user_info`(`user_id`,`user_name`,`user_pwd`,`create_time`,`update_time`) values (1,'霸刀宋一','111','2020-11-19 15:22:44','2020-11-19 15:22:47'),(2,'愛神丁二','222','2020-11-19 15:23:28','2020-11-19 15:23:53');/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

數據表text字段

create table news_info:news_content ? ? ? ? text comment '新聞內容'——text 大文本

數據表主鍵說明

小型數據庫:主鍵字段可以使用int。

大型數據庫(數據太多):分庫分表。

多表連接查詢

需要在數據表中插入數據!

SELECT user_info.`user_name`,news_item.`item_name` FROM user_info INNER JOIN item_user ON user_info.`user_id` = item_user.`user_id`INNER JOIN news_item ON item_user.`item_id` = news_item.`item_id`WHERE user_name = '張三';SELECT user_info.`user_name`,news_item.`item_name`,news_info.`news_title` FROM user_info INNER JOIN item_user ON user_info.`user_id` = item_user.`user_id`INNER JOIN news_item ON item_user.`item_id` = news_item.`item_id`INNER JOIN news_info ON news_info.`item_id` = news_item.`item_id`WHERE user_name = '張三';

今天老師主要講了數據庫的一些操作,收獲甚多,謝謝觀看~

總結

以上是生活随笔為你收集整理的Bootstrap4+MySQL前后端综合实训-Day04-PM【PowerDesigner 图形化数据库设计软件(设置依赖关系、自动增长主键、生成sql语句)、SQLyog软件(备份数据库)】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。