• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

候乐

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

sql语句

mysql -u用户名 -p密码

quit 登出数据库 exit退出数据库

show databases ; 查看所有数据库

create database 数据库名 charset=utf8;

use 数据库名; 使用数据库

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

show tables; 查看所有库

create table 表名( 字段名称 类型 条件 条件, ); 类型就是数据类型 条件里面有 非空 主键 不重复 大于几小于几 只能是“男”“女” 等等一类

desc 表名; 查看表的基础信息 在表中语句中里面排序的作用 其实查看也是排序中的一种 一般都是先查询好后 在最后添加字段

alter table 表名 add 列名 类型 约束条件;在表中添加的字段

alter table 表名 modify 列名 类型 约束 ; 修改表中的字段

alter table 表名 change 原名 新名 类型 约束条件; 修改表中已有字段名字

alter table 表名 drop 列名 ;删除表中字段

show create table 表名; 查看创表SQL语句

show create database 数据库名; 查看创库SQL语句

drop table 表名; 删除表

select * from 表名; 查询所有列

select 列1,列2,... from 表名; 查询指定列

insert into 表名 values (...) 全列插入:值的顺序与表结构字段的顺序完全一一对应

insert into 表名 (列1,...) values(值1,...) 部分列插入:值的顺序与给出的列顺序对应

insert into 表名 values(...),(...); 全列多行插入

insert into 表名(列1,...) values(值1,...),(值1,...)...; 部分列多行插入

update 表名 set 列1=值1,列2=值2... where 条件 修改数据

delete from 表名 where 条件 删除数据 (条件 字段= 值) 物理删除 一般不好恢复

alter table students add isdelete bit default 0; (添加字段) update students set isdelete = 1 where id = 8; (本质就是修改操作)一般使用逻辑删除 虽然他删除了 但是本身还是存在的 就是意义上是删除了

select id as 序号, name as 名字, gender as 性别 from students; 使用 as 给字段起别名

select id ,name ,gender from stu;单表查询 select stu.id,stu.name,stu.gender from stu; 不仅仅是单表时候带着表名

select distinct 列1.... from 表名 取出重复数据

select 字段 form 表名 where 条件; where条件查询语法格式 where后面跟着运算符 如 id>1 id=1 多个(id>2 and name = 10)

select * from 表名 limit start,count start表示开始行索引,默认是0 count表示查询条数

 

添加主键 alter table 表名 add primary key(列)

删除主键 alter table 表名 drop primary key(列)

 

 

posted on 2020-04-03 19:01  候乐  阅读(132)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3