数据库简单操作
//查看版本号
select version();
//查看本地所有的数据库
show databases;
//查什么写什么
select ‘xxxx’;
//切换数据库
use test;
//查看所有的表
show tables;
//退出
Exit
Select 查询
Insert 插入数据
Update 更新数据
Delete 删除数据
Drop 删除表
Create 创建表
SQL分类:
DCL数据控制语言(Data Control Language)
代表关键字:grant,revoke.
DDL数据定义语言(Data Definition Language)
代表关键字:create ,drop,
DML数据操作语言(Data Manipulation Language)
代表关键字:insert,delete,update
DQL数据查询语言(Data Query Language)
代表关键字:select
TCL事务控制语言(Transactional Control Language)
代表关键字:commit ,rollback;
创建数据库
语法:create table 表名(
列名 类型,
列名 类型,
);
CREATE TABLE `student_info1` (
`student_name` varchar(255) DEFAULT NULL,
`student_age` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE if not exists `student_info` (
`student_name` varchar(255) DEFAULT NULL,
`student_age` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `student_info3` (
`student_name` varchar(255) DEFAULT NULL,
`student_age` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Insert
语法
insert into 表名 (列名1,列名2) values (值1,值2);
insert into student_info (student_name,student_age) values ('二狗',23);
Update
语法
update 表名 set 列名1=值 , 列名2=值 where 列名 = 值;
update student_info set student_age=66 where student_name='二狗';
Delete
语法
delete from 表名 where 列名 = 值;
delete from student_info where student_name='二狗';
select:
语法
select 列限定 from 表限定 where 行限定
select student_name from student_info where student_age=23;
select * from student_info;