一、操作表記錄(增刪改查,create,read,update,delete)
1.insert
insert into table_name [(column [,column.....])] values (value [,value......]);
insert into employee (id,name,gender,birthday,entry_data,job,salay,resume)
values (null,'賴澤銨','男','1996-7-7','2018-12-8','python工程師',5000,'啥都會');
insert into employee values (null,'吳志雄','男','2000-1-1','2001-2-2','董事長','1','全靠他了'),(null,'賴澤銨','男','1996-7-7','2018-12-8','python工程師',5000,'啥都會'); #所有列都寫入可以不寫 ,插入多條
2.update
update tbl_name set col_name=exprl [,col_name2=expr2......]
(1)將所有員工薪水改為5000
update employee set salay= 5000;
(2)將賴澤銨薪水改為3000
update employee set salay = 3000 where name='賴澤銨';
(3)將侯文澤薪水改為4000,job改為c++
update employee set salay = 4000,job = 'c++' where name = '侯文澤';
(4)將鄭嘉穎薪水增加1000
update employee set salay = salay+1000 where name = '鄭嘉穎';
3.delet (truncate) #truncate整表摧毀
delete from table_name [where where_definition]
(1)刪除表中名為侯文澤的記錄
delete from employee where name = '侯文澤';
(2)刪除表中所有記錄
delete from employee;
(3)使用truncate刪除表中記錄
truncate employee;
4.select
select [distinct] * | from table;
(1)查詢表中所有員工的資訊
select * from employee;
(2)查詢表中所有員工的姓名和薪水
select name,salay from employee;
(3)過濾表中重複資料
select distinct salay from employee;
(4)在所有員工薪水上+1000
select name,salay+1000 from employee;
(5)統計每個學生的總分
create table grade (
id int primary key auto_increment,
name varchar(20),
chinese int,
math int,
english int
insert into grade values (null,'侯文澤',70,80,90),(null,'鄭嘉穎',79,85,92),(null,'賴澤銨',90,90,40);
select name,chinese+math+english from grade;
(6)使用別名表示學生的總分
select name as 姓名 ,chinese+math+english as 總成績 from grade;
select name 姓名 ,chinese+math+english 總成績 from grade;
5.帶有where的查詢
(1)查詢姓名為***的學生成績
select * from grade where name = '賴澤銨';
(2)查詢英語成績大於90的同學
select * from grade where english>90;
(3)查詢總分大於230分的所有同學
select * from grade where chinese+math+english>230;
(4)where 常用運算子
~:> < <= >= = <>#不等於
select * from grade where chinese<>80;
~:between ... and .... #在之間
select * from grade where math between 70 and 85;
~:in(set) #括號內為集合
select * from grade where english in (80,85,90);
~:like #像,萬用字元% ,『_』 表示乙個字元
select * from grade where name like '賴%';
select * from grade where name like '文';
~:and or not #邏輯運算子
十天學會PHP
username password 處理檔案是這樣 require once conn.php session start username post username password post password exec select from admin where username user...
mysql增刪改查效果 mysql增刪改查
檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...
mysql增刪改查擴充套件 MySQL增刪改查
1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...