MySQL 常用

mysql -u root -p
数据库-表-数据

1、分号结束
2、符号都是英文状态下的

查看数据库
show databases;  

创建数据库
create database student;

删除数据库
drop database student;

进入数据库
use student;

查看表
show tables;

"创建表" 123  字段 数据类型 约束条件, 主键
create table stu(
    sno  int(11) primary key,
    name varchar(20),
    sex  varchar(10) default "男",
    age  int(11) default 10
);



删除表
drop table stu;

查看表结构
desc stu;

数据的增删改查
查询:
select tname,rsex from stu ;
select * from student where sname like "%李%" ;
select * from teacher where tname = "李诚" and tsex = "男";
select * from teacher where tname = "王萍" or tsex = "男";
增加:
insert into stu values("张三","男",12),("李四","男",12);
insert into stu(name,age) values("李四",12);
删除
delete from student  ;
修改
update student set  sname = "张三" ;

修改字段名称  用 as  

 

 

SQL功能 动词
数据查询 select

数据操纵 insert,update,delete

关系运算:>,=,<,>=,>=,!=(<>)
范围运算:between...and;
空判断:is null,is not null;
IN判断:in,not in,exists(复杂查询)
模糊查询:like,not like
逻辑运算 and与 or或 not非


 

posted @ 2017-11-18 16:12  空城花开  阅读(148)  评论(0编辑  收藏  举报