随笔分类 - mysql
摘要:mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | +----+----------+-------+-----------+ | 1 | xiaoming | 89 | shuxue | | 2 | xiaohong | ...
阅读全文
摘要:mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | +----+----------+-------+-----------+ | 1 | xiaoming | 89 | shuxue | | 2 | xiaohong | ...
阅读全文
摘要:成绩最高 成绩最低
阅读全文
摘要:mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | +----+----------+-------+-----------+ | 1 | xiaoming | 89 | shuxue | | 2 | xiaohong | ...
阅读全文
摘要:mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | +----+----------+-------+-----------+ | 1 | xiaoming | 89 | shuxue | | 2 | xiaohong | ...
阅读全文
摘要:%匹配任意长度 _ 匹配单个字符
阅读全文
摘要:mysql> select * from table1; +----------+------------+-----+---------------------+-------+ | name_new | transactor | pid | order_date | price | +----------+------------+-----+-------------...
阅读全文
摘要:假设id为主键,id可以保证字段数据唯一性,但是一张表只有一个主键。主键的值:修改成的0,可以存在,就是排个序。新添加的0,不允许存在,要根据行号改变。本身存在的0,不允许存在,要从1开始递增变化。Insert 进去 id = 0的数据,数据会从实际的行数开始增加 参考: https://www.c
阅读全文
摘要:唯一键特点: 1、唯一键在一张表中可以有多个。 2、唯一键允许字段数据为NULL,NULL可以有多个(NULL不参与比较) //一个表中允许存在多个唯一键,唯一键允许为空,在不为空的情况下,不允许重复 //设置一个字段为唯一键 mysql> alter table `table1` add unique ( `name_new`); Query OK, 0 rows affected (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...
阅读全文
摘要: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;
阅读全文
摘要://修改字段长度 alter table table1 modify name char(15); //修改字段名称以及长度 alter table table1 change name name_new char(32); alter table table1 change id id int(10);
阅读全文
摘要://重命名表 rename table table1 to table2; //重命名多个表 rename table table1 to table2,table3 to table4,table5 to table6;
阅读全文
摘要://创建数据库 create database testdata; //切换数据库 use testdata; //创建表 create table table1(id int,name varchar(10)); //插入值 insert table1(id,name) values(1,"xiaoming");
阅读全文
摘要://offset参数指定要返回的第一行的偏移量。第一行的偏移量为0,第二行的偏移量为1。count指定要返回的最大行数。LIMIT offset,count;
阅读全文
摘要:默认不指定,order by 按照升序排列。 asc:升序 desc:降序
阅读全文
摘要:mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah...
阅读全文
摘要:mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah...
阅读全文
摘要:mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | transactor | pid | order_date | +----------+------------+-----+---------------------+ | 1hah...
阅读全文