mysql中的增删改查

插入命令

insert into test_name (id) values (10);
insert into test_name values (10, ‘bobbb’, 55, ‘2020-10-10’);

插入数据

	插入多条数据
	
	```javascript
	insert into test_name values(3, 'gansby', 45, '1999-10-09');
	insert into test_name values(4, 'res', 12, '1999-10-09');
	insert into test_name values(5, 'pink', 55, '1999-10-09');
	insert into test_name values(6, 'yellow', 43, '1999-10-09');
	insert into test_name values(7, 'red', 56, '1999-10-09');

	-------------------------------------------------------------------
	// 输入后显示如下

	mysql> insert into test_name values(3, 'gansby', 45, '1999-10-09');
	Query OK, 1 row affected (0.01 sec)
	
	mysql> insert into test_name values(4, 'res', 12, '1999-10-09');
	Query OK, 1 row affected (0.00 sec)
	
	mysql> insert into test_name values(5, 'pink', 55, '1999-10-09');
	Query OK, 1 row affected (0.00 sec)
	
	mysql> insert into test_name values(6, 'yellow', 43, '1999-10-09');
	Query OK, 1 row affected (0.00 sec)
	
	mysql> insert into test_name values(7, 'red', 56, '1999-10-09');
	Query OK, 1 row affected (0.01 sec)


	结果
	 select * from test_name;
	+------+--------+------+------------+
	| id   | name   | age  | date       |
	+------+--------+------+------------+
	|    1 | bob    |   12 | 2020-12-12 |
	|    2 | blue   |   45 | 2020-10-12 |
	|    3 | gansby |   45 | 1999-10-09 |
	|    4 | res    |   12 | 1999-10-09 |
	|    5 | pink   |   55 | 1999-10-09 |
	|    6 | yellow |   43 | 1999-10-09 |
	|    7 | red    |   56 | 1999-10-09 |
	+------+--------+------+------------+
	7 rows in set (0.00 sec)

删除某条记录

	mysql> delete from test_name where name='res';
	Query OK, 1 row affected (0.00 sec)

修改某条记录

	mysql> UPDATE test_name SET name='gray' WHERE name='red';
	Query OK, 1 row affected (0.00 sec)
	Rows matched: 1  Changed: 1  Warnings: 0
  • 查看表的数据

     select * from test_name;
    +------+--------+------+------------+
    | id   | name   | age  | date       |
    +------+--------+------+------------+
    |    1 | bob    |   12 | 2020-12-12 |
    |    2 | blue   |   45 | 2020-10-12 |
    |    3 | gansby |   45 | 1999-10-09 |
    |    5 | pink   |   55 | 1999-10-09 |
    |    6 | yellow |   43 | 1999-10-09 |
    |    7 | gray   |   56 | 1999-10-09 |
    +------+--------+------+------------+
    6 rows in set (0.00 sec)
    
    
  • 查看表的信息 describe test_name; 或 desc test_name;

    mysql> describe test_name;
    +-------+--------------+------+-----+---------+-------+
    | Field | Type         | Null | Key | Default | Extra |
    +-------+--------------+------+-----+---------+-------+
    | id    | int(10)      | YES  |     | NULL    |       |
    | name  | varchar(100) | YES  |     | NULL    |       |
    | age   | int(10)      | YES  |     | NULL    |       |
    | date  | date         | YES  |     | NULL    |       |
    +-------+--------------+------+-----+---------+-------+
    4 rows in set (0.00 sec)
    

你可能感兴趣的:(mysql)