MySQL Day one
基础查询
语法:
select 查询列表(需要查的) from 表名(来源 从哪查)
查询列表可以是:表中的字段 常量值 表达式 函数
查询的结果是一个虚拟的表格
1,查询表中的单个字段
select a from test;
2,查询表中多个字段
select a,b from test;
3,查询表中所有字段
select * from test;
use test 进入test库
起别名
1,`select name as 名字,num as 数字 from shop;`
2,`select name 名字,num 数字 from shop;`
3,`select name as “a b”from shop;`
去重
distinct
eg select distinct id from shop;
安全修改表
alter table 命令可以修改表
新增字段
eg alter table new_shop add column click_num int null after product_name;默认添加在最后
删除字段
eg alter table new_shop2 drop column click_num;
修改字段的类型等用change modify
eg alter table new_shop2 change product_name product_name varchar(30);
alter table new_shop2 modify product_name varchar(30);
修改字段的名字只能用change
eg alter table new_shop2 change product_name product_name1 varchar(30) 最后必须加上类型