crud 對(duì)表的增刪改查
增 insert into
1.完全插入:例如:insert into 表名 values( 108401,' 學(xué)習(xí) ', 20,1,' 1245678999 ');
2.選擇插入:例如:insert into 表名(userid,name,age) values( 10000,' 小花 ',19);
3.多行插入:例如:insert into 表名(userid,name) values(19999,' 葡萄 '),(18888,‘ 辣椒 ’);
查看已經(jīng)插入的數(shù)據(jù) select * from 表名 (*表示所有)哨颂;
修改 更新 update
1.更新單個(gè)字段(列)
update 表名 set name = '小包' , age = 19 where id = 12345;
2.更新多行
update 表名 set name = ' 小包' ;
3.更新多個(gè)字段(列)
update 表名 set name = ' 小包 ' age = 19 where id = 18888 ;
將一個(gè)表復(fù)制到另一個(gè)表中
insert into 新表 (列名,列名...) select 列名,列名... from 原表 ;
刪除數(shù)據(jù) delete
刪除特定的一行:例如:delete from 表名 where id = 10010 ;
刪除所有行:例如:delete from 表名 (不能輕易做);
查詢
查詢所有 select * from 表名∨缡小;
查詢某一個(gè) select * from 表名 where id = 13333 ;
查詢年齡這個(gè)列 select age from 表名 where id = 19999威恼;
使用限定的方式查找品姓,不進(jìn)入數(shù)據(jù)庫就可以查詢到表的信息
select * from 數(shù)據(jù)庫名.表名;
使用 distinct 去重寝并,返回不重復(fù)的列的值
select distinct age from 表名;insert into 表 (列名,列名...) select 列名,列名... from 表
數(shù)據(jù)庫的查詢 where(過濾)
查詢一行 select * from 表名 where age = 6「贡浮衬潦;
where 條件查詢和運(yùn)算符
= 等于 select * from 表名 where age = 6 ;
<> 不等于, != 不等于植酥,< 小于镀岛, <= 小于等于, > 大于惧互, >= 大于等于哎媚,
between ... and 在兩者之間(包含邊界值);
例如:select name ,age from 表名 where age between 5 and 30 ;
is null 判斷某一列的數(shù)據(jù)喇伯,如果包含null 喊儡,則返回記錄;
例如:select * from 表名 where phone is null ;
and 鏈接查詢條件,查詢的數(shù)據(jù)要全部滿足
例如:select name from 表名 where userid>=18004 and age>99;
or 鏈接查詢條件,查詢的數(shù)據(jù)只要滿足其中一個(gè)即可
例如:select name from 表名 where userid>=18004 or age>90;
in 操作符 (相當(dāng)于 or ) in (條件1稻据,條件2艾猜,條件3);
例如:selete name(列)