mysql 表操作
时间:2021-07-01 10:21:17
帮助过:4人阅读
MariaDB [(none)]
> create database db1 charset utf8
;
# 切换文件夹
MariaDB [(none)]
> use db1
;
# 创建文件表
MariaDB [db1]
> create table t1(
-> id int,
-> name varchar(
50),
-> sex enum(
‘male‘,
‘female‘),
-> age
int(
3)
-> )
;
#查看db1库下所有表名
MariaDB [db1]
> show tables
;
# 查看表结构
MariaDB [db1]
> desc t1
;
+-------+-----------------------+------+-----+---------+-------+
| Field
| Type
| Null
| Key
| Default
| Extra
|
+-------+-----------------------+------+-----+---------+-------+
| id | int(
11)
| YES
| | NULL
| |
| name
| varchar(
50)
| YES
| | NULL
| |
| sex
| enum(
‘male‘,
‘female‘)
| YES
| | NULL
| |
| age
| int(
3)
| YES
| | NULL
| |
+-------+-----------------------+------+-----+---------+-------+
# 查看表中的某些字段
MariaDB [db1]
> select
id,name,sex,age
from t1
;
Empty
set (
0.00 sec)
# 查看表中的所有字段
MariaDB [db1]
> select
* from t1
;
Empty
set (
0.00 sec)
# 向表文件中插入整行
MariaDB [db1]
> insert into t1 values
-> (
1,
‘egon‘,
18,
‘male‘),
-> (
2,
‘alex‘,
81,
‘female‘)
-> ;
MariaDB [db1]
> select
* from t1
;
+------+------+------+--------+
| id | name
| age
| sex
|
+------+------+------+--------+
| 1 | egon
| 18 | male
|
| 2 | alex
| 81 | female
|
+------+------+------+--------+
# 往表中插入数据(特定的字段)
MariaDB [db1]
> insert into t1(
id) values
-> (
3),
-> (
4)
;
MariaDB [db1]
> select
* from t1
;
+------+------+------+--------+
| id | name
| age
| sex
|
+------+------+------+--------+
| 1 | egon
| 18 | male
|
| 2 | alex
| 81 | female
|
| 3 | NULL
| NULL
| NULL
|
| 4 | NULL
| NULL
| NULL
|
+------+------+------+--------+
mysql 表操作
标签:不能 lock type 不同 data 约束 -- none sql