首頁  >  文章  >  資料庫  >  了解mysql基本語法

了解mysql基本語法

迷茫
迷茫原創
2017-03-26 13:07:401270瀏覽

建立表格 

create table <表名>(
 <字段名>  类型(长度) not null primary key auto_increment, **主键
 name char(20) not null,  
 sex int(4) not null default &#39;0&#39;, **默认键
 degree double(16,2)
)

刪除表格

drop table <表名>;
//情空表
delete from <表名>;

插入資料

insert into <表名> [( <字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]

查詢表格

select <字段1,字段2,...> from < 表名 > where < 表达式 >

查詢表的前幾個欄位

#
select * from MyClass order by id limit 0,2;

查詢欄位總和

select sum('欄位名稱') from 表名

 查詢欄位依照升序降序排列

 降序:select *  from   表名  where  表達式  order by  字段名 desc

 升序:select  *  from   表名  where  Putout=true  ## by time   表名表  where  Putout=true  ## by time) 修改表

#re#白表##>

delete from 表名 where 表达式

新增表格欄位

alter table 資料表名稱add 欄位類型其他;

    <1  主鍵:alter table 資料表名稱add primary key (欄位名稱);

    <2  唯一約束:alter table 表名add unique 索引名(字段名稱);

刪除表格字段

update 表名 set 字段=新值,… where 条件

以上是了解mysql基本語法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn