python七之数据库

版权声明:本文为博主原创文章,欢迎转载,注明出处即可。 https://blog.csdn.net/m0_37805490/article/details/77920292

数据库的命令:

     查看所有的数据库:show  databases:

     查看当前使用的数据库:select database():

     切换数据库:use 数据库名:

     创建数据库:create database   数据库名  charset = utf8:

     删除数据库:drop database 数据库名:


数据表的命令:

    查看所有表:show tables:

    创建表:create table 表名(id int auto_increment primary key not null、、、)

     删除表:drop table 表名:

//(一般不要使用删除语句,或者选用逻辑删除,选中表,创建一个新栏位,命名为isdelete,使其有0和1两个值,我们想把某个值删除时可以使其isdelete值为1,然后利用数据库表的筛选功能,只让其显示出isdelete==0的数据,这样显示出来的直接就是为未删除的信息,这样逻辑上的删除就防止重要数据数据的丢失)

     修改表:alter table 表名  add|change|drop  列

//创建的表中必须有主键!!!!否则创建不成功,会有以下提示:


数据的命令:

      查询:select  *from 表名  (后可加条件:where name like '...' or name like '...':):

      增加:insert  into 表名 values(...):

      修改:update 表名 set 字段=值...

      删除:delete  from 表名

范围查询:select *from students where id in( , , ):   //使用in!!!

查询一个连续的范围:select  *from students where id between 3 and 8:  // between...and...

空判断:null不占用内存,‘  ’空字符串也为空,但是有占用内存


猜你喜欢

转载自blog.csdn.net/m0_37805490/article/details/77920292