1. 程式人生 > >mysql學習筆記2

mysql學習筆記2

create table tablename( )

建立資料庫表的命令, 列的名稱以及該列的資料型別將在括號內完成;

括號內的內容:id, name, sex, age, tel每列的名稱,列與列的描述用,隔開。

id int unsigned not null auto_increment primary 


向表中插入資料

insert   [into]   表名   [(列名1, 列名2, 列名3...)]   values  (值1, 值2, 值3...);

例:insert   into  students  values(...);

如果出現   query ok   那麼表示資料插入成功。

如果插入部分資料時候:

insert   into   students(name,  sex,  age) values('name',  ''sex',  age);


查詢表中的資料:(最重要,我也是因為工作需要才學習mysql,專案已經成熟, 一般做的只是些查詢而已)

select 根據查詢規則到資料庫獲取資料。

select  列名  from  表名  [查詢條件];

假設查詢學生姓名和性別:select   name,  sex   from   students;

select  *  from   students;  查詢所有

  

where關鍵詞用於查詢的條件,一般為:select   *  from  students  where  age  >= 12;

列出所有的年齡大於12 的學生的資訊。


更新表:update  表名  set  列名=新的value  where  條件;

例如:update  students  set  age=21 where name=lili;


刪除:delete   from  表名  where  條件;


最後推薦幾個不錯的mysql學習網址:


http://blog.csdn.net/chinacodec/article/details/5797127


http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html#c1