1.数据库操作
#sql语句最后都加上英文的 ;
-显示当前数据库版本
select version();
-显示时间
select now();
-查看所有数据库
show databases;
-创建数据库
creat database python4 charset=utf-8;
-删除数据库
drop database 数据库名;
-使用数据库
use数据库名
use python-04;
-查看当前使用的数据库
select database();
2.数据表的操作
2.1 数据表操作
-查看当前数据库中所有的表
show tables;
-desc查看表的结构
desc xxxxx;
-创建数据表
create table python04 (字段 类型 约束1,字段 类型 约束2);
-创建一个student表(id\name\age\high\gender\cls_id)
creat table students(
id int unsigned not null auto_increment primary key , #unsigned表示正数的意思 primary key 是主键的意思
name varchar(30),
age tinyint unsigned default 0,
high decimal(5,2),
gender enum(“男”,"女","中性",“保密”)default “保密”,
cls_id int unsigned
);
-删除表
-drop database 数据库名;
-drop table 数据表名;
-显示表的创建语句
-show create table student;
2.1 字段增删改查
-增加字段
alter table 表名字 add 字段
alter table student add birthday datatime;
-修改字段
-不重命名
alter table student modify 列名 类型和约束
alter table student modify birthday date;
-重新命名
alter table student change 原名 新名 类型和约束
alter table student change birthday birth date default "1990-01-01";
-删除字段
alter table student drop high;
2.2 数据的增删改查
-查询基本使用
-查询所有数据
select * from student;
-制定查询条件