Mysql 常用增删改查命令集合教程
创建:create 插入:insert 更新:update
查询:select 删除:delete 修改:alter 销毁:drop
创建一个数据库:
create database 数据库名 [其他选项];
create database `samp_db`;
创建数据库表:
create table 表名称(列声明);
create table `students`
(
`id` int unsigned not null auto_increment primary key,
`name` char(8) not null,
`sex` char(4) not null,
`age` tinyint unsigned not null,
`tel `char(13) null default "-"
)ENGINE=MyISAM charset=utf8;
向表中插入数据:
insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);
insert into `students` set `name`='王刚',`sex`='男',`age`='20',`tel`='13811371377';
insert into `students` values(NULL, "王刚", "男", 20, "13811371377");
查询表中的数据:
select 列名称 from 表名称 [查询条件];
select `name`,`age` from `students`;
或者使用通配符查询:
select * from `students`;
按特定条件查询:
select 列名称 from 表名称 where 条件;
select * from `students` where `sex`="女";
where 子句条件支持(=、>、<、>=、<、!= 以及一些扩展运算符 is [not] null、in、like 等等,还可以对查询条件使用 or 和 and 进行组合查询)
select * from `students` where `age` > 21;
select * from `students` where `name` like "%王%";
select * from `students` where `id`<5 and `age`>20;
更新表中的数据:
update 表名称 set 列名称=新值 where 更新条件;
将id为5的手机号改为默认的"-":
update `students` set `tel`=default where `id`=5;
将所有人的年龄增加1:
update `students` set `age`=age+1;
将手机号为 13288097888 的姓名改为 "张伟鹏", 年龄改为 19:
update `students` set `name`="张伟鹏", `age`=19 where tel="13288097888";
删除表中的数据:
delete from 表名称 where 删除条件;
删除id为2的行:
delete from `students` where `id`=2;
删除所有年龄小于21岁的数据:
delete from `students` where `age`<20;
删除表中的所有数据:
delete from `students`;
创建后表的修改:
添加列:
alter table 表名 add 列名 列数据类型 [after 插入位置];
在表的最后追加列 address:
alter table `students` add `address` char(60);
在名为 age 的列后插入列birthday:
alter table `students` add `birthday date after `age`;
修改列:
alter table 表名 change 列名称 列新名称 新数据类型;
将表 tel 列改名为 telphone:
alter table `students` change `tel` `telphone` char(13) default "-";
将 name 列的数据类型改为 char(16):
alter table `students` change `name` `name` char(16) not null;
删除列:
alter table 表名 rename 新表名;
删除 birthday 列:
alter table students drop `birthday`;
重命名表:
alter table 表名 rename 新表名;
重命名 students 表为 workmates:
alter table `students` rename `workmates`;
删除整张表:
drop table 表名;
删除 workmates 表:
drop table `workmates`;
删除整个数据库:
drop database 数据库名;
删除 samp_db 数据库:
drop database `samp_db`;
Mysql 常用增删改查命令集合教程的更多相关文章
- mysql常用增删改查命令(纯纪录.orm用得基本功都没了。)
更新表数据: update table_name set xxx=xxx where condition; 增加字段: alter table table_name add field type ot ...
- MySQL常用增删改查等操作语句
修改数据库的字符集 mysql>use mydb mysql>alter database mydb character set utf8;创建数据库指定数据库的字符集 ...
- 如何创建数据库以及MySQL增删改查命令的简单运用
在已经安装好MySQL的前提下 1.在Windows打开命令提示符窗口,输入命令启动MySQL命令行工具并登入root用户:mysql -h localhost -u root -p 2.输入密码后, ...
- zkCli的使用 常用的节点增删改查命令用法
zkCli的使用 常用的节点增删改查命令用法 1. 建立会话 命令格式:zkCli.sh -timeout 0 -r -server ip:port ./zkCli.sh -server -time ...
- MySQL之增删改查之
MySQL之增删改查 前言:以下是MySQL最基本的增删改查语句,很多IT工作者都必须要会的命令,也是IT行业面试最常考的知识点,由于是入门级基础命令,所有所有操作都建立在单表上,未涉及多表操作. ...
- MySql之增删改查 · YbWork's Studio
前提:在进行"增删改查"的操作之前,先建立一个包含数据表student的数据库(具体操作可以见MySQL之最基本命令): 1."增"--添加数据 1.1 为表中 ...
- Java连接MySQL数据库增删改查通用方法
版权声明:本文为博主原创文章,未经博主允许不得转载. Java连接MySQL数据库增删改查通用方法 运行环境:eclipse+MySQL 以前我们Java连接MySQL数据库都是一个数据库写一个类,类 ...
- 三分钟小课堂-----------------docker(三)增删改查命令
主要为docker容器的增删改查命令 1 创建容器: docker run -it --name 别名 image_name /bin/bash --name 别名 -d 后台 -t ...
- Redis的增删改查命令总结与持久化方式
原文:Redis的增删改查命令总结与持久化方式 Redis是用C语言实现的,一般来说C语言实现的程序"距离"操作系统更近,执行速度相对会更快. Redis使用了单线程架构,预防了多 ...
随机推荐
- DB2 57016报错的解决办法(表状态不正常,导致表无法操作)
新建了一张表,删除了一列,然后执行insert的时候,报错 57016,解释为:因为表不活动. 1.执行db2 "load query table <tabname>" ...
- redis做消息列队
#encoding:utf8 import time import redis conn = redis.Redis('localhost',db=1) #连接诶数据库并使用数据库1 def inse ...
- 六、Prototype 原型设计模式
需求:使用 new 生成实例需要指定类名,在不指定类的情况下生成实例 代码清单: 原型接口 Product: public interface Product extends Cloneable{ v ...
- 【Django】django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?
今天创建APP的时候报这个错误django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you in ...
- java 1.8
rpm -qa|grep java (列出本机已安装的java,没有则没空)rpm -e --nodeps 文件名(上一步查到的文件名,一个一个复制过来卸载就好.) 下载java包 https://w ...
- JAVA jar 参数
-client to select the "client" VM -server to select the "server" ...
- CardView 卡片布局
转自:https://www.baidu.com/link?url=WwHvfX3PB_egfQ6GFwxsDeq4NDzB2AW-zaTzskkNXs0qWnIcHyh3pN3Oqe6YO1lAmV ...
- Vue Baidu Map 插件的使用
最近在做一个项目,技术采用的是Vue.js套餐,有个百度地图的需求,当时,大脑宕机,立马去引入百度地图API,当时想到两种方法,一种是在index.html中全局引入js,此法吾不喜,就采用了第二种异 ...
- gdb打印C++容器
将以下内容保存成 .gdbinit 文件放到你的根目录,或者在gdb中source这个文件可以加载. 直接print容器即可. # # STL GDB evaluators/views/utiliti ...
- Mac Sublime Text3 如何安装插件
1.打开sublime text3后按快捷键control+`后下面会出来东西,然后输入如下命令. import urllib.request,os; pf = 'Package Control.su ...