常用入門SQL語句之增刪改查

1、增:

    insert into 表名(字段名1,字段名2,...) values(值1,值2,...):

    insert into 表名 values(值1,值2,...):

    insert into 表名():    括號內不指定自增字段\默認字段相應字段也會取得值

    alert table stu_info add(addr char(50));


2、刪:

    delete from 表名 

    where 篩選條件;(例:字段名=1/num=1) 刪除一行


    truncate 不可恢復性刪除

    drop 直接刪除表


3、改:

    update 表名 set 字段名1=新值1,字段名2=新值2... where 篩選條件;

    select name as sname,phone as phone_num from stu_info;

    select * from stu_info order by chinese asc/desc;   語文成績列按照升序/降序排列

    select num,sname,math,chinese,math+chinese as zong from stu_info order by zong desc;   

    將數學列和語文列成績相加新建總分列,並且按降序排列


4、查:

    select 字段名1,字段名2... from 表名                        篩選顯示兩列數據

    select * from stu_info limit 0,1;                                從第0行開始顯示一行(第0行就是第一行)

    select * from stu_info where gender='M';               篩選性別爲男的數據

    select * from stu_info where name like '%趙';          篩選出名字爲~趙 的人 

    select * from stu_info where name like '趙%';          篩選出姓趙的人的數據

    select * from stu_info where name not like '趙%';    篩選出不姓趙的人

    select * from stu_info where gender='M' limit 0,2;  性別爲男的人顯示前兩行數據

    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章