ALTER命令
(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
(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ù)量
(9)字符串函數(shù)與update、set搭配使用
表中有的列中不符合原子性,不利于查詢,利用字符串可以很好地將不具有原子性的列拆分成兩列或多列
總結(jié)
- 上一篇: 最强安卓机?三星S23系列宣传物料曝光
- 下一篇: 寺庙内设电子扫码烧金 最低八块八网友感慨