MySQL 将数据库字段增大 1?
你可以使用更新命令对数据库进行增量。语法如下 -
UPDATE yourTableName set yourColumnName=yourColumnName+1 where condition;
为了了解上述语句,我们先创建一个表格。创建表格的查询如下 -
mysql> create table IncrementBy1 -> ( -> Id int, -> Name varchar(100), -> CounterLogin int -> ); Query OK, 0 rows affected (0.63 sec)
使用插入命令插入一些记录。在表格中插入记录的查询如下 -
mysql> insert into IncrementBy1 values(100,'John',30); Query OK, 1 row affected (0.17 sec) mysql> insert into IncrementBy1 values(101,'Carol',50); Query OK, 1 row affected (0.15 sec) mysql> insert into IncrementBy1 values(102,'Bob',89); Query OK, 1 row affected (0.25 sec) mysql> insert into IncrementBy1 values(103,'Mike',99); Query OK, 1 row affected (0.18 sec) mysql> insert into IncrementBy1 values(104,'Sam',199); Query OK, 1 row affected (0.36 sec) mysql> insert into IncrementBy1 values(105,'Tom',999); Query OK, 1 row affected (0.18 sec)
使用选择语句显示表格中的所有记录。查询如下 -
mysql> select *from IncrementBy1;
输出
+------+-------+--------------+ | Id | Name | CounterLogin | +------+-------+--------------+ | 100 | John | 30 | | 101 | Carol | 50 | | 102 | Bob | 89 | | 103 | Mike | 99 | | 104 | Sam | 199 | | 105 | Tom | 999 | +------+-------+--------------+ 6 rows in set (0.00 sec)
以下是将数据库字段增大 1 的查询 -
mysql> update IncrementBy1 -> set CounterLogin=CounterLogin+1 -> where Id=105; Query OK, 1 row affected (0.45 sec) Rows matched: 1 Changed: 1 Warnings: 0
现在,你可以检查特定的记录是否已增大。值 999 已增加 1,这是因为我们正在增加 Id=105 的值,如上所示。
以下是检查记录的查询 -
mysql> select *from IncrementBy1 where Id=105;
输出
+------+------+--------------+ | Id | Name | CounterLogin | +------+------+--------------+ | 105 | Tom | 1 000 | +------+------+--------------+ 1 row in set (0.00 sec)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP