摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+-------+ | name_new | transactor | pid | order_date | price | +----------+------------+-----+-------------... 阅读全文
posted @ 2019-08-04 23:45
anobscureretreat
阅读(473)
评论(0)
推荐(0)
摘要:
假设id为主键,id可以保证字段数据唯一性,但是一张表只有一个主键。主键的值:修改成的0,可以存在,就是排个序。新添加的0,不允许存在,要根据行号改变。本身存在的0,不允许存在,要从1开始递增变化。Insert 进去 id = 0的数据,数据会从实际的行数开始增加 参考: https://www.c 阅读全文
posted @ 2019-08-04 23:27
anobscureretreat
阅读(5279)
评论(0)
推荐(0)
摘要:
唯一键特点: 1、唯一键在一张表中可以有多个。 2、唯一键允许字段数据为NULL,NULL可以有多个(NULL不参与比较) //一个表中允许存在多个唯一键,唯一键允许为空,在不为空的情况下,不允许重复 //设置一个字段为唯一键 mysql> alter table `table1` add unique ( `name_new`); Query OK, 0 rows affected (0.0... 阅读全文
posted @ 2019-08-04 23:25
anobscureretreat
阅读(1533)
评论(0)
推荐(0)
摘要:
//不允许为null alter table table1 change id id int(10) not null; //允许为null alter table table1 change id id int(10) null; //name_new允许为空 insert table1(id,transactor) values(1,"world"); //transactor... 阅读全文
posted @ 2019-08-04 23:21
anobscureretreat
阅读(8472)
评论(0)
推荐(0)
摘要:
mysql> alter table table1 add price int(10) not null; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 //删除一个字段 ALTER TABLE table1 drop id; 阅读全文
posted @ 2019-08-04 23:20
anobscureretreat
阅读(381)
评论(0)
推荐(0)
摘要:
//修改字段长度 alter table table1 modify name char(15); //修改字段名称以及长度 alter table table1 change name name_new char(32); alter table table1 change id id int(10); 阅读全文
posted @ 2019-08-04 23:18
anobscureretreat
阅读(8141)
评论(0)
推荐(0)
摘要:
//重命名表 rename table table1 to table2; //重命名多个表 rename table table1 to table2,table3 to table4,table5 to table6; 阅读全文
posted @ 2019-08-04 23:16
anobscureretreat
阅读(538)
评论(0)
推荐(0)
摘要:
//创建数据库 create database testdata; //切换数据库 use testdata; //创建表 create table table1(id int,name varchar(10)); //插入值 insert table1(id,name) values(1,"xiaoming"); 阅读全文
posted @ 2019-08-04 23:15
anobscureretreat
阅读(178)
评论(0)
推荐(0)
摘要:
//offset参数指定要返回的第一行的偏移量。第一行的偏移量为0,第二行的偏移量为1。count指定要返回的最大行数。LIMIT offset,count; 阅读全文
posted @ 2019-08-04 23:08
anobscureretreat
阅读(161)
评论(0)
推荐(0)
摘要:
例子 例子 例子 阅读全文
posted @ 2019-08-04 22:55
anobscureretreat
阅读(693)
评论(0)
推荐(0)
摘要:
默认不指定,order by 按照升序排列。 asc:升序 desc:降序 阅读全文
posted @ 2019-08-04 22:46
anobscureretreat
阅读(2495)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:44
anobscureretreat
阅读(665)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:27
anobscureretreat
阅读(381)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:21
anobscureretreat
阅读(3165)
评论(0)
推荐(0)
摘要:
如下,可以看到使用后,也统计了null的个数。 阅读全文
posted @ 2019-08-04 22:16
anobscureretreat
阅读(336)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:14
anobscureretreat
阅读(640)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:06
anobscureretreat
阅读(374)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 22:00
anobscureretreat
阅读(2173)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 21:52
anobscureretreat
阅读(10917)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 21:41
anobscureretreat
阅读(11504)
评论(0)
推荐(0)
摘要:
mysql> select * from table1 where minute(order_date)=46; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+-... 阅读全文
posted @ 2019-08-04 21:36
anobscureretreat
阅读(1038)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 21:29
anobscureretreat
阅读(3146)
评论(0)
推荐(0)
摘要:
mysql> select tan(pi()/4); +--------------------+ | tan(pi()/4) | +--------------------+ | 0.9999999999999999 | +--------------------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:25
anobscureretreat
阅读(271)
评论(0)
推荐(0)
摘要:
mysql> select pi(); +----------+ | pi() | +----------+ | 3.141593 | +----------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:24
anobscureretreat
阅读(1014)
评论(0)
推荐(0)
摘要:
mysql> select mod(16,3); +-----------+ | mod(16,3) | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:21
anobscureretreat
阅读(2807)
评论(0)
推荐(0)
摘要:
mysql> select sqrt(16); +----------+ | sqrt(16) | +----------+ | 4 | +----------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:19
anobscureretreat
阅读(546)
评论(0)
推荐(0)
摘要:
mysql> select sin(PI()/6); +---------------------+ | sin(PI()/6) | +---------------------+ | 0.49999999999999994 | +---------------------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:18
anobscureretreat
阅读(570)
评论(0)
推荐(0)
摘要:
//获取pi 阅读全文
posted @ 2019-08-04 21:16
anobscureretreat
阅读(588)
评论(0)
推荐(0)
摘要:
mysql> select abs(3-5); +----------+ | abs(3-5) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:15
anobscureretreat
阅读(13490)
评论(0)
推荐(0)
摘要:
mysql> select exp(1); +-------------------+ | exp(1) | +-------------------+ | 2.718281828459045 | +-------------------+ 1 row in set (0.00 sec) 阅读全文
posted @ 2019-08-04 21:13
anobscureretreat
阅读(967)
评论(0)
推荐(0)
摘要:
mysql> select rand(); +--------------------+ | rand() | +--------------------+ | 0.9913473352709294 | +--------------------+ 1 row in set (0.00 sec) mysql> select rand()*100; +--------... 阅读全文
posted @ 2019-08-04 21:11
anobscureretreat
阅读(776)
评论(0)
推荐(0)
摘要:
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah... 阅读全文
posted @ 2019-08-04 20:53
anobscureretreat
阅读(44331)
评论(0)
推荐(3)
摘要:
alter table table1 add order_date datetime null; mysql> select * from table1; +----------+------------+-----+------------+ | name_new | transactor | pid | order_date | +----------+------------+... 阅读全文
posted @ 2019-08-04 20:48
anobscureretreat
阅读(2908)
评论(0)
推荐(0)
摘要:
参考: https://www.yiibai.com/mysql/mysql_function_addtime.html 阅读全文
posted @ 2019-08-04 20:33
anobscureretreat
阅读(1169)
评论(0)
推荐(0)
摘要:
mysql> select adddate('1998-01-02', 31); +---------------------------+ | adddate('1998-01-02', 31) | +---------------------------+ | 1998-02-02 | +---------------------------+ 1 row ... 阅读全文
posted @ 2019-08-04 20:32
anobscureretreat
阅读(752)
评论(0)
推荐(0)
摘要:
定义和用法 DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。 语法 date 参数是合法的日期。format 规定日期/时间的输出格式。 可以使用的格式有: 参考: https://www.w3school.com.cn/sql/func_date_format.asp 阅读全文
posted @ 2019-08-04 20:22
anobscureretreat
阅读(215)
评论(0)
推荐(0)
摘要:
mysql> select curtime(); +-----------+ | curtime() | +-----------+ | 19:43:34 | +-----------+ 1 row in set (0.00 sec) mysql> select time(now()); +-------------+ | time(now()) | +-------------+ |... 阅读全文
posted @ 2019-08-04 20:13
anobscureretreat
阅读(156)
评论(0)
推荐(0)
摘要:
参考: https://www.w3school.com.cn/sql/sql_dates.asp 阅读全文
posted @ 2019-08-04 20:11
anobscureretreat
阅读(172)
评论(0)
推荐(0)
摘要:
mysql> select dayofweek(curdate())-1; +------------------------+ | dayofweek(curdate())-1 | +------------------------+ | 0 | +------------------------+ 1 row in set (0.00 sec) ... 阅读全文
posted @ 2019-08-04 20:10
anobscureretreat
阅读(6828)
评论(0)
推荐(0)
摘要:
定义和用法 DATEDIFF() 函数返回两个日期之间的天数。 语法 date1 和 date2 参数是合法的日期或日期/时间表达式。 注释:只有值的日期部分参与计算。 参考: https://www.w3school.com.cn/sql/func_datediff_mysql.asp 阅读全文
posted @ 2019-08-04 20:09
anobscureretreat
阅读(573)
评论(0)
推荐(0)
摘要:
定义和用法 DATE_ADD() 函数向日期添加指定的时间间隔。 语法 date 参数是合法的日期表达式。expr 参数是您希望添加的时间间隔。 type 参数可以是下列值: 参考: https://www.w3school.com.cn/sql/func_date_add.asp 阅读全文
posted @ 2019-08-04 20:07
anobscureretreat
阅读(250)
评论(0)
推荐(0)
摘要:
当前表 根据发音查找内容 阅读全文
posted @ 2019-08-04 19:39
anobscureretreat
阅读(256)
评论(0)
推荐(0)
摘要:
当前表: 选择出名字,并且转为大写 阅读全文
posted @ 2019-08-04 19:32
anobscureretreat
阅读(3508)
评论(0)
推荐(0)
摘要:
1 第一范式(1NF)在任何一个关系数据库中,第一范式(1NF)是对关系模式的基本要求,不满足第一范式(1NF)的数据库就不是关系数据库。所谓第一范式(1NF)是指数据库表的每一列都是不可分割的基本数据项,同一列中不能有多个值,即实体中的某个属性不能有多个值或者不能有重复的属性。如果出现重复的属性, 阅读全文
posted @ 2019-08-04 16:12
anobscureretreat
阅读(122)
评论(0)
推荐(0)
摘要:
1)范式优化: 比如消除冗余(节省空间。。) 2)反范式优化:比如适当加冗余等(减少join) 3)拆分表: 分区将数据在物理上分隔开,不同分区的数据可以制定保存在处于不同磁盘上的数据文件里。这样,当对这个表进行查询时,只需要在表分区中进行扫描,而不必进行全表扫描,明显缩短了查询时间,另外处于不同磁 阅读全文
posted @ 2019-08-04 15:35
anobscureretreat
阅读(246)
评论(0)
推荐(0)
摘要:
SQL语句优化 1)应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描。2)应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如:select id from t where num is null可以在n 阅读全文
posted @ 2019-08-04 14:30
anobscureretreat
阅读(181)
评论(0)
推荐(0)
摘要:
视图是虚拟的表,与包含数据的表不一样,视图只包含使用时动态检索数据的查询;不包含任何列或数据。 使用视图可以简化复杂的sql操作,隐藏具体的细节,保护数据;视图创建后,可以使用与表相同的方式利用它们。视图不能被索引,也不能有关联的触发器或默认值,如果视图本身内有order by 则对视图再次orde 阅读全文
posted @ 2019-08-04 14:11
anobscureretreat
阅读(1337)
评论(0)
推荐(0)
摘要:
数据库事务transanction正确执行的四个基本要素。ACID,原子性(Atomicity)、一致性(Correspondence)、隔离性(Isolation)、持久性(Durability)。原子性:整个事务中的所有操作,要么全部完成,要么全部不完成,不可能停滞在中间某个环节。事务在执行过程 阅读全文
posted @ 2019-08-04 14:10
anobscureretreat
阅读(467)
评论(0)
推荐(0)
摘要:
查询显示当前的隔离级别 设置隔离级别 查看隔离级别也可以(前提是知道具体变量名): 参考: https://www.jianshu.com/p/6738c4b11da8 阅读全文
posted @ 2019-08-04 13:31
anobscureretreat
阅读(14194)
评论(0)
推荐(0)
摘要:
详解: Read uncommitted A事务可以读取未提交事务B的数据 会出现的问题: 脏读: B事物修改数据a=1,但是没有提交,A事物读取数据a=1,A事物拿到数据后显示,此时B事物回滚,再次修改数据a=2,然后提交,所以实际数据a=2,但是A事物拿到的是a=1. Read committe 阅读全文
posted @ 2019-08-04 13:12
anobscureretreat
阅读(960)
评论(0)
推荐(0)
摘要:
原子性(Atomicity):一个事务要么都执行,要么都回滚(不可再分割) 一致性(Consistency):保证数据的状态操作前和操作后保持一致 隔离性(Isolation):多个事务同时操作相同数据库的同一个数据时,一个事务的执行不受另外一个事务的干扰 持久性(Durability):一个事务一 阅读全文
posted @ 2019-08-04 11:53
anobscureretreat
阅读(898)
评论(0)
推荐(0)
摘要:
1.脏读:一个事务读取到了另外一个事务未提交的数据,读到其他事务的未提交的“更新”数据 2.不可重复读:同一个事务中,多次读取到的数据不一致 3.幻读:一个事务读取到了另外一个事务未提交的数据,只是读到的是其他事务“插入”的数据 阅读全文
posted @ 2019-08-04 11:27
anobscureretreat
阅读(1276)
评论(0)
推荐(0)
摘要:
当多个事务同时操作同一个数据库的相同数据时。 阅读全文
posted @ 2019-08-04 11:22
anobscureretreat
阅读(180)
评论(0)
推荐(0)
摘要:
数据库模式定义语言并非程序设计语言,DDL数据库模式定义语言是SQL语言(结构化查询语言)的组成部分。 SQL语言包括四种主要程序设计语言类别的语句:数据定义语言(DDL),数据操作语言(DML),数据控制语言(DCL)和事务控制语言(TCL)。 阅读全文
posted @ 2019-08-04 11:02
anobscureretreat
阅读(200)
评论(0)
推荐(0)
摘要:
数据操纵语言(Data Manipulation Language, DML)是SQL语言中,负责对数据库对象运行数据访问工作的指令集。 以INSERT、UPDATE、DELETE三种指令为核心,分别代表插入、更新与删除,是开发以数据为中心的应用程序必定会使用到的指令, 因此有很多开发人员都把加上S 阅读全文
posted @ 2019-08-04 10:43
anobscureretreat
阅读(385)
评论(0)
推荐(0)
摘要:
//Truncate是一个能够快速清空资料表内所有资料的SQL语法。并且能针对具有自动递增值的字段,做计数重置归零重新计算的作用。 阅读全文
posted @ 2019-08-04 10:25
anobscureretreat
阅读(171)
评论(0)
推荐(0)
摘要:
1、Mysql 让主键归0:TRUNCATE table1; 2、只清空数据表,主键不归0:DELETE FROM table1; 参考: https://www.csdn.net/gather_2d/MtTaMgxsMjcxMy1ibG9n.html 阅读全文
posted @ 2019-08-04 01:10
anobscureretreat
阅读(799)
评论(0)
推荐(0)
摘要:
1、TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行。但 TRUNCATE TABLE 比 DELETE 速度快,且使用的系统和事务日志资源少。 2、DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一项。TRUNCATE 阅读全文
posted @ 2019-08-04 01:03
anobscureretreat
阅读(634)
评论(0)
推荐(0)
摘要:
1、由 FOREIGN KEY 约束引用的表。(您可以截断具有引用自身的外键的表。) 2、参与索引视图的表。 3、通过使用事务复制或合并复制发布的表。 4、对于具有以上一个或多个特征的表,请使用 DELETE 语句。 5、TRUNCATE TABLE 不能激活触发器,因为该操作不记录各个行删除。 阅读全文
posted @ 2019-08-04 00:56
anobscureretreat
阅读(509)
评论(0)
推荐(0)
摘要:
1.drop和delete只是删除表的数据(定义),drop语句将删除表的结构、被依赖的约束(constrain)、触发器 (trigger)、索引(index);依赖于该表的存储过程/函数将保留,但是变为invalid状态。 2.delete语句是DML语言,这个操作会放在rollback seg 阅读全文
posted @ 2019-08-04 00:54
anobscureretreat
阅读(232)
评论(0)
推荐(0)

浙公网安备 33010602011771号