mysql增查删改

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: mysql> use test Database changed mysql> create table class ( -> id int primary key auto_increment, -> sname varchar(10) not null default '', -> gender char(1) not n
mysql> use test
Database changed
mysql> create table class (
    -> id int primary key auto_increment,
    -> sname varchar(10) not null default '',
    -> gender char(1) not null default '',
    -> company varchar(20) not null default '',
    -> salary decimal(6,2) not null default 0.00,
    -> fanbu smallint not null default 0
    -> )engine myisam charset utf8;
Query OK, 0 rows affected (0.11 sec)

mysql> desc class;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| sname   | varchar(10)  | NO   |     |         |                |
| gender  | char(1)      | NO   |     |         |                |
| company | varchar(20)  | NO   |     |         |                |
| salary  | decimal(6,2) | NO   |     | 0.00    |                |
| fanbu   | smallint(6)  | NO   |     | 0       |                |
+---------+--------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)

mysql> insert into class 
    -> (id,sname,gender,company,salary,fanbu)
    -> values
    -> (1,'张三','男','百度',8889.23,250);
Query OK, 1 row affected (0.05 sec)

mysql> insert into class
    -> (sname,gender,salary)
    -> values
    -> ('科比','男',9000);
Query OK, 1 row affected (0.00 sec)

mysql> select * from class;
+----+--------+--------+---------+---------+-------+
| id | sname  | gender | company | salary  | fanbu |
+----+--------+--------+---------+---------+-------+
|  1 | 张三   | 男     | 百度    | 8889.23 |   250 |
|  2 | 科比   | 男     |         | 9000.00 |     0 |
+----+--------+--------+---------+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into class
    -> values
    -> (3,'李四','女','新浪',5888.90,125);
Query OK, 1 row affected (0.00 sec)

mysql> insert into class
    -> values
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
mysql> insert into class
    -> (sname,company,salary)
    -> values
    -> ('刘备','皇室',1000.00),
    -> ('孙策','江东集团',8000.00),
    -> ('曹操','魏国',5000.00);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from class;
+----+--------+--------+--------------+---------+-------+
| id | sname  | gender | company      | salary  | fanbu |
+----+--------+--------+--------------+---------+-------+
|  1 | 张三   | 男     | 百度         | 8889.23 |   250 |
|  2 | 科比   | 男     |              | 9000.00 |     0 |
|  3 | 李四   | 女     | 新浪         | 5888.90 |   125 |
|  4 | 刘备   |        | 皇室         | 1000.00 |     0 |
|  5 | 孙策   |        | 江东集团     | 8000.00 |     0 |
|  6 | 曹操   |        | 魏国         | 5000.00 |     0 |
+----+--------+--------+--------------+---------+-------+
6 rows in set (0.00 sec)

mysql> update class set gender='男' where id=4;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from class;
+----+--------+--------+--------------+---------+-------+
| id | sname  | gender | company      | salary  | fanbu |
+----+--------+--------+--------------+---------+-------+
|  1 | 张三   | 男     | 百度         | 8889.23 |   250 |
|  2 | 科比   | 男     |              | 9000.00 |     0 |
|  3 | 李四   | 女     | 新浪         | 5888.90 |   125 |
|  4 | 刘备   | 男     | 皇室         | 1000.00 |     0 |
|  5 | 孙策   |        | 江东集团     | 8000.00 |     0 |
|  6 | 曹操   |        | 魏国         | 5000.00 |     0 |
+----+--------+--------+--------------+---------+-------+
6 rows in set (0.00 sec)

mysql> select * from class\G
*************************** 1. row ***************************
     id: 1
  sname: 张三
 gender: 男
company: 百度
 salary: 8889.23
  fanbu: 250
*************************** 2. row ***************************
     id: 2
  sname: 科比
 gender: 男
company: 
 salary: 9000.00
  fanbu: 0
*************************** 3. row ***************************
     id: 3
  sname: 李四
 gender: 女
company: 新浪
 salary: 5888.90
  fanbu: 125
*************************** 4. row ***************************
     id: 4
  sname: 刘备
 gender: 男
company: 皇室
 salary: 1000.00
  fanbu: 0
*************************** 5. row ***************************
     id: 5
  sname: 孙策
 gender: 
company: 江东集团
 salary: 8000.00
  fanbu: 0
*************************** 6. row ***************************
     id: 6
  sname: 曹操
 gender: 
company: 魏国
 salary: 5000.00
  fanbu: 0
6 rows in set (0.00 sec)


 

#建立文件,并把操作mysql表的内容全部显示
tee F:\1230.sql
#学生表
create table class (
id int primary key auto_increment,
sname varchar(10) not null default '',
gender char(1) not null default '',
company varchar(20) not null default '',
salary decimal(6,2) not null default 0.00,
fanbu smallint not null default 0
)engine myisam charset utf8;

#查看表的结构
desc class;
#增加一条信息
insert into class 
(id,sname,gender,company,salary,fanbu)
values
(1,'张三','男','百度',8889.23,250);

#特殊情况
insert into class
(sname,gender,salary)
values
('科比','男',9000);

#插入所有列
insert into class
values
(3,'李四','女','新浪',5888.90,125);

#插入多列
insert into class
(sname,company,salary)
values
('刘备','皇室',1000.00),
('孙策','江东集团',8000.00),
('曹操','魏国',5000.00);

#修改
update class set gender='男' where id=4;

#全部改
update class set fanbu=100 where 1;
#where 1 ,1 表示真,1恒为真

#删除
delete from class where id=1;

#查询
select * from class;


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
14天前
|
NoSQL 关系型数据库 MySQL
【MySQL探索之旅】MySQL数据表的增删查改——约束
【MySQL探索之旅】MySQL数据表的增删查改——约束
|
5月前
|
关系型数据库 MySQL 数据库
【MySQL学习】MySQL表的增删改查操作2
【MySQL学习】MySQL表的增删改查操作
86 0
|
9月前
|
关系型数据库 MySQL 数据库
超详细的mysql多表操作教程
超详细的mysql多表操作教程
35193 20
|
9月前
|
SQL Oracle 关系型数据库
|
5月前
|
存储 SQL 关系型数据库
【mysql】MySQL基础
【mysql】MySQL基础
|
5月前
|
关系型数据库 MySQL 数据库
【MySQL学习】MySQL表的增删改查操作1
【MySQL学习】MySQL表的增删改查操作
115 1
|
5月前
|
Oracle 关系型数据库 MySQL
【MySQL学习】MySQL表的增删改查操作3
【MySQL学习】MySQL表的增删改查操作
56 0
|
5月前
|
存储 关系型数据库 MySQL
【MySQL学习】MySQL表的操作
【MySQL学习】MySQL表的操作
55 1
|
5月前
|
存储 关系型数据库 MySQL
【MySQL】快速了解MySQL基础
【MySQL】快速了解MySQL基础
|
11月前
|
SQL 存储 监控
MySQL的SQL基础应用
MySQL的SQL基础应用
97 0