洛陽網(wǎng)站排名百家號查詢排名數(shù)據(jù)查詢
添加數(shù)據(jù)
我們對?testdatabase 數(shù)據(jù)中 的 qqemp 這張表進行 增加數(shù)據(jù),在這張表 下 打開 命令行
query console 在 軟件中就是打開命令行的意思
可以先執(zhí)行 desc qqemp; 查看一下當前表的結(jié)構(gòu)。
插入一條數(shù)據(jù) 到qqemp 表,插入時要每個字段都有值
insert into qqemp values (001,'zhangsan',98787);
插入一條數(shù)據(jù) 到qqemp 表,只有 id 和name 字段
insert into qqemp (id,name) values (002,'lisi');
insert into qqemp (id,name) values (002,'lisi');
插入多條數(shù)據(jù) 到qqemp 表,只有 id 和name 字段,插入了三條值
insert into qqemp (id,gongzi) values (003,333),(004,444),(005,555);
插入多條數(shù)據(jù) 到qqemp 表,所有的字段都有,插入了三條值
insert into qqemp values (006,'a006',66666),(007,'a007',77777),(008,'a008',88888);
結(jié)果
給 emp_info 表中添加一項數(shù)據(jù)
可以通過desc emp_info 查看這張表中有哪些字段,或者通過 show create table emp_info查看 emp_info這張表的create 語句。
show create table emp_info;
CREATE TABLE `emp_info` (`id` int DEFAULT NULL COMMENT '編號',`workernumber` varchar(10) DEFAULT NULL COMMENT '員工工號',`workername` varchar(10) DEFAULT NULL COMMENT '員工姓名',`workergender` char(1) DEFAULT NULL COMMENT '員工性別',`age` tinyint unsigned DEFAULT NULL COMMENT '員工年齡',`idcard` char(18) DEFAULT NULL COMMENT '員工身份證號',`entrydate` date DEFAULT NULL COMMENT '員工入職時間',`newstudentnumber` float(3,1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
desc emp_info;
insert into
insert into emp_info(id, workernumber, workername, workergender, age, idcard, entrydate, newstudentnumber) values (001,'hw000001','sw000001','男',28,'111111222222333333','2014-09-30',89.5);
如果插入的元素 在 create語句的時候可以為null,則插入的時候可以填null,否則不行
insert into emp_info values (002,'hw000002',null,'男',28,null,'2014-09-30',89.5);
修改數(shù)據(jù)
update 表名 set 字段名1=值1, 字段名2=值2,..... [where 條件];
如果沒有where 條件,則會修改整張表的所有數(shù)據(jù)。因此一些軟件會提示,讓程序員進一步的確認,如果不想進一步確認,可以將沒有where條件,寫成 where 1=1;
修改id為1的數(shù)據(jù),將name 修改為 itheima
update qqemp set name='itheima' where id =1;修改id為2的數(shù)據(jù),將name修改為小昭,將gongzi改成80000 update qqemp set name='小昭', gongzi=80000 where id =2;將所有員工的入職日期改為 2008-01-01 update qqemp set joindate="2008-01-01" where 1=1;
刪除數(shù)據(jù)
delete from 表名 [where 條件];
如果沒有where 條件,則會刪除整張表的所有數(shù)據(jù)。
eg :將所有name為null的數(shù)據(jù)刪除
delete from qqemp where name is null;
eg: 刪除姓名為itheima的數(shù)據(jù)
delete from qqemp where name='itheima';
eg:刪除整張表
delete from qqemp;