《Mysql學習mysql中alter、update、insert、delete、show語句的例子》要點:
本文介紹了Mysql學習mysql中alter、update、insert、delete、show語句的例子,希望對您有用。如果有疑問,可以聯系我們。
導讀:本節內容:alter、update、insert、delete、show語句的用法舉例.一,alter table命令用來轉變數據表的許多設計細節,如添加或刪除一些數...
MYSQL數據庫本節內容:
alter、update、insert、delete、show語句的用法舉例.
MYSQL數據庫一,alter table命令
用來改變數據表的許多設計細節,如添加或刪除一些數據列,改變數據列的屬性,界說和刪除各種索引等.
MYSQL數據庫1,增加數據列
?
alter table tblname add newcolname coltype coloptions
MYSQL數據庫2,改動數據列
alter table tblname change oldcolname newcolname coltype coloptions
例如:
alter table table1 change id id auto_increment
MYSQL數據庫闡明列沒有改名,也也可實現改名
MYSQL數據庫3,刪除數據列
?
alter table tblname drop colname
MYSQL數據庫4,增加索引
?
alter table tblname add primary key (indexcols)
alter table tblname add index [indexname] (indexcols)
alter table tblname add unique [indexname] (indexcols)
MYSQL數據庫5,添加外鍵約束條件
?
alter table tblname add foreign key [indexname] (column1) references table2 (column2)
MYSQL數據庫6,刪除索引
?
alter table tblname drop primary key
alter table tblname drop index indexname
alter table tblname drop foreign key indexname
MYSQL數據庫二,update命令用來改動數據庫里現有的數據記錄
1,where限定的update語句
?
update tablename
set column1=value1,column2=value2
where columnN=value
MYSQL數據庫2,不帶where限定的update對整個數據表做改動
?
update titles set? year=2005
update titles set price=price*1.05
MYSQL數據庫3,編纂排列清單里的數據記錄
?
update tablename set mydata=0 order by name limit 10
MYSQL數據庫4,更新關聯數據內外的數據記錄
?
update table1,table2
set table1.columnA = table2.columnB
where table1.table1ID = table2.table1ID
MYSQL數據庫三,insert命令可以向表中插入數據
1,一條命令插入多條數據記載
?
insert into table (columnA columnB columnC)
values('a',1,2),('b',12,13),('c',22,33),
MYSQL數據庫四,delete命令用于刪除表中記錄
delete from titles where titleID=8//因為刪除肯定是刪除一行記錄,所以delete后不必要加*
MYSQL數據庫1,刪除聯系關系記錄
?
delete t1,t2 from t1,t2,t3 where condition1 and condition2
MYSQL數據庫2,輸出排序清單里的數據記載
?
delete from authors order by ts desc limit 1
MYSQL數據庫五,show敕令,查看原數據:
?
show databases
show tables from dbname
show [full] columns from tablename //返回全體數據列的詳細信息
show index from tablename
歡迎參與《Mysql學習mysql中alter、update、insert、delete、show語句的例子》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.fzlkiss.com/jiaocheng/13700.html