日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ALTER命令

發(fā)布時間:2023/12/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ALTER命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

(1)添加列作為主鍵(id行,自動增加),并放在第一列——add

alter table doughnut_list add column doughnut_id int not null auto_increment first, add primary key(doughnut_id);

(2)添加某一列,并指定放在某一列后面——add

alter table doughnut_list add column phone varchar(10) after doughnut_id;

同理,也可以使用before your_column、last、second、third等。
(3)修改表名——rename

alter table old_name rename to new_name;

(4)修改列名——change

alter table table_name change column old_columnname new_columnname int;

(5)修改列數(shù)據(jù)類型——modify

alter table table_name modify column column_name newtype;

(6)刪除某一列——drop

alter table table_name drop column column_name;

(7)刪除主鍵

alter table table_name drop primary key;

(8)字符串函數(shù)
right( )和left( )可從列中選出指定數(shù)量的字符串
substring_index( )則可以選取部分列值
upper(your_string)和lower(your_string)分別把整組字符串改為大寫或小寫
reverse(your_string)反轉(zhuǎn)字符串中的字符順序
ltrim(your_string)和rtrim(your_string)會返回消除多余空格后的字符串,分別清除字符左側(cè)和右側(cè)的多余空格
length(your_string)返回字符串的字符數(shù)量

select right("location",2) select right(column_name,2) from table_name select substring_index(your_string,start_position,length) select substring_index('location',5,1) /*提取出第1個逗號前的字符*/ select substring_index(column_name,',',1) from table_name /*若提取第1個逗號和第二個逗號之間,可先把第1個逗號之前刪除*/ substr(insterests,length(interest1)+2)

(9)字符串函數(shù)與update、set搭配使用
表中有的列中不符合原子性,不利于查詢,利用字符串可以很好地將不具有原子性的列拆分成兩列或多列

update my_contacts set state=right(location,2);

總結(jié)

以上是生活随笔為你收集整理的ALTER命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。