mysql中查看库中某个表的所有列和对应的字段类型
执行命令:
select COLUMN_NAME ,DATA_TYPE from information_schema.COLUMNS where table_name = '表名' and table_schema = '数据库名';
例:我想查看我的"student"数据库,表"user"中有哪些字段,以及字段的类型都是什么
select COLUMN_NAME ,DATA_TYPE from information_schema.COLUMNS where table_name = 'user' and table_schema = 'student';
结果:
+-------------+-----------+
| COLUMN_NAME | DATA_TYPE |
+-------------+-----------+
| id | int |
| name | varchar |
| passwd | varchar |
| cnname | varchar |
| email | varchar |
| phone | varchar |
| im | varchar |
| qq | varchar |
| role | tinyint |
| creator | int |
| created | timestamp |
+-------------+-----------+
补充知识:
如果想更改user表中某个具体学生的某个值,例:更改lisan的电话为123或者让他的手机号为空则执行如下的命令:
改为123:
UPDATE user SET phone="123" where name="lisan";
改为空:
UPDATE user SET phone="" where name="lisan";