数据库操作记录
2019-05-05 本文已影响0人
DragonRat
数据库添加字段
ALTER TABLE people ADD COLUMN name VARCHAR(100) DEFAULT NULL COMMENT '姓名'
删除一个字段
alter table user DROP COLUMN new2; //删除一个字段
修改一个字段
alter table user MODIFY new1 VARCHAR(10); //修改一个字段的类型
alter table user CHANGE new1 new4 int; //修改一个字段的名称,此时一定要重新指定该字段的类型
设置自增id初始值
alter table users AUTO_INCREMENT=10000;
清空数据表
DELETE FROM st_order WHERE 1=1
在laravel项目中打印sql
DB::connection()->enableQueryLog(); // 开启QueryLog
//sql语句
var_dump(DB::getQueryLog());
按小时日周月分组
//小时
select DATE_FORMAT(create_time,'%Y%m%d%H') hours,count(caseid) count from tc_case group by hours;
//按天统计:
select DATE_FORMAT(start_time,'%Y%m%d') days,count(product_no) count from test group by days;
//按周统计:
select DATE_FORMAT(start_time,'%Y%u') weeks,count(product_no) count from test group by weeks;
//按月统计:
select DATE_FORMAT(start_time,'%Y%m') months,count(product_no) count from test group bymonths;
多表联合跟新
UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name=c.name , c.stu_name=s.name
来源:[https://blog.csdn.net/u012604745/article/details/80642015](https://blog.csdn.net/u012604745/article/details/80642015)