创建一个数据库
MySQL localhost:33060+ ssl SQL > create database bala;
Query OK, 1 row affected (0.0113 sec)
选择使用的数据库
use bala;
创建库表
MySQL localhost:33060+ ssl bala SQL > create table bala_tb1(
-> 用户ID char(10),
-> 姓名 char(6),
-> 年龄 int(3), -
> 地址 varchar(40)
-> )
-> charset=utf8;
Query OK, 0 rows affected, 2 warnings (0.0685 sec)
查看库表的信息
describe demo.table1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| 姓名 | char(10) | YES | | NULL | |
| 性别 | char(1) | YES | | NULL | | | 年龄 | int | YES | | NULL | | | 地址 | varchar(40) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+
插入数据到数据表
MySQL localhost:33060+ ssl bala SQL > insert bala_tb1(用户ID,姓名,年龄,地址)values(0001,'张三','20','广州天河');
Query OK, 1 row affected (0.0183 sec)
MySQL localhost:33060+ ssl bala SQL > SELECT * from bala_tb1;
+--------+------+------+----------+
| 用户ID | 姓名 | 年龄 | 地址 |
+--------+------+------+----------+
| 1 | 张三 | 20 | 广州天河 |
+--------+------+------+----------+ 1
row in set (0.0066 sec)
插入列
MySQL localhost:33060+ ssl bala SQL > ALTER TABLE bala_tb1 add 入职时间 varchar(20);
Query OK, 0 rows affected (0.1188 sec) Records: 0 Duplicates: 0 Warnings: 0
MySQL localhost:33060+ ssl bala SQL > SELECT * from bala_tb1;
+--------+--------+------+----------+----------+
| 用户ID | 姓名 | 年龄 | 地址 | 入职时间 |
+--------+--------+------+----------+----------+
| 1 | 张三 | 20 | 广州天河 | NULL |
| 2 | 张四 | 27 | 广州番禺 | NULL |
| 3 | 莉莉丝 | 17 | 北京朝阳 | NULL |
+--------+--------+------+----------+----------+
3 rows in set (0.0019 sec)
更新数据的内容
MySQL localhost:33060+ ssl bala SQL > UPDATE bala_tb1 set 薪资=10000 where 用户ID=1;
Query OK, 1 row affected (0.0110 sec) Rows matched: 1 Changed: 1 Warnings: 0
MySQL localhost:33060+ ssl bala SQL > SELECT * from bala_tb1;
+--------+--------+------+----------+-------+----------+
| 用户ID | 姓名 | 年龄 | 地址 | 薪资 | 入职时间 |
+--------+--------+------+----------+-------+----------+
| 1 | 张三 | 20 | 广州天河 | 10000 | NULL |
| 2 | 张四 | 27 | 广州番禺 | NULL | NULL |
| 3 | 莉莉丝 | 17 | 北京朝阳 | NULL | NULL |
+--------+--------+------+----------+-------+----------+
3 rows in set (0.0021 sec)
删除数据库表的列
MySQL localhost:33060+ ssl bala SQL > ALTER TABLE bala_tb1 drop column 入职时间;
Query OK, 0 rows affected (0.0520 sec)
Records: 0 Duplicates: 0 Warnings: 0
删除数据库的数据
MySQL localhost:33060+ ssl bala SQL > SELECT * from bala_tb1;
+--------+------+------+----------+-------+
| 用户ID | 姓名 | 年龄 | 地址 | 薪资 |
+--------+------+------+----------+-------+
| 1 | 张三 | 20 | 广州天河 | 10000 |
| 2 | 张四 | 27 | 广州番禺 | NULL |
+--------+------+------+----------+-------+
2 rows in set (0.0014 sec)
MySQL localhost:33060+ ssl bala SQL >
清空表内容
MySQL localhost:33060+ ssl bala SQL > DELETE FROM bala_tb1;
Query OK, 2 rows affected (0.0056 sec)
MySQL localhost:33060+ ssl bala SQL > SELECT * from bala_tb1;
Empty set (0.0018 sec)
MySQL localhost:33060+ ssl bala SQL >
删除表
MySQL localhost:33060+ ssl bala SQL > DROP table bala_tb1;
Query OK, 0 rows affected (0.0340 sec)
网友评论