關於一些常用的SQL語句

2021-10-01 02:45:19 字數 546 閱讀 4176

增加欄位並標明備註:

alter table test  add  test_name varchar(220) comment '名稱'
刪除的話,在實際情況中最好不要刪除資料,可以增加棄用的狀態去控制

表備份:

備份test 表生成test_new ,新錶的命名根據你們的具體要求來

create table test_new as select * from test;
索引-新增索引:

test :是表名

test_n1:是新增的索引的名稱

test_name :是索引字段

alter table test add index test_n1(test_name )
索引-刪除索引:

test_n1 :是索引名稱

test :是表名

drop index test_n1 on test ;
索引方面的東西可參考這個大佬的文章

一些常用的 sql語句總結

查詢賣最好的商品名稱 select goods name from indent detail group by goods id order by sum goods num limit 1 查詢張三購買過的商品名稱 select goods name from user join indent ...

MySQL的一些常用SQL語句

備份表 create table 新錶 select from 舊表 建立臨時表 create temporary table tablename id varchar 100 name varchar 100 age varchar 100 刪除臨時表 drop temporary table i...

記錄一些常用的sql語句

select name,submittime from enterprise where yearweek date format submittime,y m d yearweek now select name,submittime from enterprise where yearweek ...