mysql使用的增删改查语句

查看(下面对应有例子)

斜体样式查看数据库的所有信息语句:select * from 表名
查看表单的某一列信息:select 列的表头 from 表名:
查看表单某一行的数据:select * from mybook.book where 列明对应的值;
查看表单的数据条数:select count(
) from mybook.book; 返回是数据的条数
查看匹配的条数:select count(*) as count from mybook.book where name=‘西游记’ and author=‘吴承恩’;

  • select * from mybook.book where name=‘成功一辈子’;
  • 最好是id因为id不重复

select * from mybook.book;
delete from mybook.book where id=‘8’;
select * from mybook.book where name=‘成功一辈子’;
select id from mybook.book;
查看返回的是查询的匹配的数目
select count() from mybook.book;
select count(
) as count from mybook.book where name=‘西游记’ and author=‘吴承恩’;

删除

  • 用id删除直接用
    delete from mybook.login where id=‘2’;
  • 但是其他就得加一条语句
    SET SQL_SAFE_UPDATES=0;
    delete from mybook.login where name=‘luck’;
  • 删除全部
    delete from mybook.login;
    delete from mybook.login where name=‘luck’;

增加

语法: insert into 数据库.表明 (列头) values (对应数据);

insert into mybook.login values (‘power’,‘456’);
insert into mybook.login (name,pwd) values (‘power1’,‘4561’);
insert into mybook.login (id,name,pwd) values (NULL,‘power12’,‘45611’);

注意前面括号的不加双引号 null也没有双引号

修改

语法: update 数据库.表名 set 要设置的字段 where id= ;

update mybook.login set name=‘worker’ where id=‘10’;

上一篇:Python元编程详细教程


下一篇:编辑器 gitbook