MySQL从小白到总裁完整教程目录:https://blog.csdn.net/weixin_67859959/article/details/129334507?spm=1001.2014.3001.5502
语法格式:
desc 表名;
描述:
如果表不存在,就提示不存在;
如果表存在,就显示表的结构
比如:
desc test01;
desc test02;
错误示范:
mysql> desc 666;
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 '666' at line 1
有的可能因为版本的不同,报错的原因有所区别,但是问题不大
正确的:
mysql> desc test01;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)
mysql> desc test02;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(8) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| gender | char(3) | YES | | NULL | |
| score | double(4,1) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.03 sec)
两个表还是不够用,再来创建一个表吧
create table test03(name varchar(30), #姓名age int(3), #年龄salary double(8,2), #工资etime date, #入职日期address varchar(50) #地址
);
为下次做准备
练习:创建一张表,表名为work01,表中包含的字段有:
wid int
wname varchar(30)
gender char(3)
score double(4,1)
wtime date
address varchar(50)
create table work01(wid int,wname varchar(30),gender char(3),score double(4,1),wtime date,address varchar(50)
);