栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

MySql之删除和修改和插入

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySql之删除和修改和插入

MySql之删除和修改和插入

建表语句

create table m_blog_three
(
    oldtime     datetime                           not null on update CURRENT_TIMESTAMP,
    id          bigint                             not null
        primary key,
    user_id     bigint                             not null,
    title       varchar(255)                       not null,
    description varchar(255)                       not null,
    content     longtext                           null,
    created     datetime                           not null on update CURRENT_TIMESTAMP,
    status      tinyint                            null,
    helloone    bigint                             null,
    threetime   datetime default CURRENT_TIMESTAMP null
)
    charset = utf8mb4;

插入数据

INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 1, 1, '文章一', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-17 17:36:11', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 2, 1, '文章一2', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-17 17:36:11', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 3, 2, '文章一3', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-18 11:38:56', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 4, 3, '文章一4', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-18 11:38:56', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 5, 2, '文章一5', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-18 11:38:56', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 6, 4, '文章一6', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-06-18 11:38:56', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 7, 4, '文章一7', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-09-29 17:45:29', 0, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('2021-09-30 14:20:14', 8, 5, '文章一8', '1', '第一篇文章第一篇文章第一篇文章', '2021-09-30 14:20:14', null, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 9, 5, '文章一8', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-09-29 17:46:21', null, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 10, 5, '文章一8', '<第一篇文章>', '第一篇文章第一篇文章第一篇文章', '2021-09-29 17:46:21', null, 100, '2021-09-30 14:32:38');
INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES ('0000-00-00 00:00:00', 11, 6, '文章一8', '第一篇文章', '第一篇文章第一篇文章第一篇文章', '2021-09-29 17:45:29', null, 100, '2021-09-30 14:32:38');
DDL和DML

在讲删除之前需要明确一下DDL和DML之间的区别。简单的来说DML操作的是表中的数据,而且数据库中是有对应数据的记录的,而且需要commit提交才可以,就是说必须执行完了之后,点击提交才可以生效,而且是可以回滚的。但是DDL的操作对象是数据库或者表,是不用提交也可以回滚的。

删除 delete-DML

delete不会变更表或者索引的大小,删除表中数据而不删除表的结构(定义),同时也不释放空间。

删除一条数据

delete from m_blog_three where id=10;

删除整个表的数据

delete from m_blog_three;
truncate-DDL

truncate通过释放存储表数据所用的数据页来删除数据,truncate会将表和索引初始化为初始大小,相当于空表

truncate table  m_blog_three;

经过试验下面这样也是可以的

truncate   m_blog_three;

再次select该表,还是可以查询到的,只是数据为空

drop-DDL

什么表结构啊什么数据什么索引啊,都没了,啥都没了

drop table m_blog_three;

再次查询,发现已经没有这个表了

插入

字符串必须得用’'或者""包裹起来,NOW()为获取当前时间的函数。

INSERT INTO testgroup.m_blog_three (oldtime, id, user_id, title, description, content, created, status, helloone, threetime) VALUES (NOW(), 12, 1, '文章12', '第12篇文章', '第12篇文章第12篇文章第12篇文章', NOW(), 0, 100, NOW());
修改
UPDATE testgroup.m_blog_three t SET t.user_id = 2 WHERe t.id = 12;
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/306541.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号