mysql命令行模式(1)

创建表

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `date1` datetime(6) DEFAULT NULL,
  `date2` date DEFAULT NULL,
  `date3` timestamp(6) NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

SET FOREIGN_KEY_CHECKS = 1;

查询

SELECT [ DISTINCT ] select_list

[ INTO new_table ]

FROM table_name

[ WHERE search_condition ]

[ GROUP BY group_by_expression ]

[ HAVING search_condition ]

[ ORDER BY order_by_expression [ ASC | DESC ] ]

视图:CRUD同表

select `user`.`id` AS `id_v`,`user`.`name` AS `name_v`,`user`.`age` AS `age_v` from `user`

别名

select name "名字" from user;

select name ’名字‘ from user; 

select name 名字 from user; 

select name as "名字" from user;

select name as ’名字‘ from user; 

select name as 名字 from user; 

嵌入行内的注释语句:

“--”(双减号)用来创建单行文本注释语句。

块注释语句:

在注释文本的起始处输入“/*”,在注释文本的结束处输入“*/”,就可以使两个符号间的所有字符称为注释语句,从而可以创建包含多行的块注释语句。

限制条数

LIMIT m OFFSET n

条件

= 

>

< 

>=

<=

!> 

!< 

!=    /   <>

逻辑运算符:注意他们的优先级

NOT

AND

OR

通配符 : % _ [] 

转义符

查询指定行

查询随机一行

(未完待续)

发布了186 篇原创文章 · 获赞 1 · 访问量 7928

猜你喜欢

转载自blog.csdn.net/qq_37769323/article/details/104217977