如何判断表的id字段是否为主键 ? sql语句 ? 如何判断表的id字段是否为主键 ? sql语句 ?请大家帮帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 desc table;还有show create table table名;用很多工具也可以呀。 mysql> show create table test;+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------| test | CREATE TABLE `test` ( `id` int(11) NOT NULL auto_increment, `name` varchar(3) default NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 |+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------mysql> select column_key -> from information_schema.columns -> where table_schema='csdn' and table_name='test' and column_name='id';+------------+| column_key |+------------+| PRI |+------------+ select id from tb where key="PRI"; zhoupuyue说的正确,根据你的数据库名,表名,列名,到information_schema这个库的columns表里查询,看你找的列对应的column_key的值是否为PRI,如果为空,就不是KEY. 5以上可以用系统表,select column_key from information_schema.columns where table_schema='csdn' and table_name='test' and column_name='id'; #3楼 select column_keyfrom information_schema.columnswhere table_schema='csdn' and table_name='test' and column_name='id'; 急!Mysql 中按成绩降序排名 取名次(每个人的名次都要有) 急,请求协助MySQL 有那些易安装的mysql数据库? 一个很奇怪得问题 在mysql中如何比较2个16进制数字? ▄◣如何实现sqlserver和mysql两个数据库之间的数据同步,最好请大斑竹来回答,急,200分在线等...?◤up也有分!◥ 在使用mysql的过程中可否和linux一样切换用户 Linux下连接不上MySQL sql 笔试题,我不会,你会吗 sql查询语句问题 Mysql插入和查询时出现乱码? JAVA+MYSQL的程序问题
还有
show create table table名;
用很多工具也可以呀。
mysql> show create table test;
+-------+----------------------------------------------------------------------
-------------------------------------------------------------------------------
| test | CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(3) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------
-------------------------------------------------------------------------------mysql> select column_key
-> from information_schema.columns
-> where table_schema='csdn' and table_name='test' and column_name='id';
+------------+
| column_key |
+------------+
| PRI |
+------------+
select id from tb where key="PRI";
select column_key
from information_schema.columns
where table_schema='csdn' and table_name='test' and column_name='id';
select column_key
from information_schema.columns
where table_schema='csdn' and table_name='test' and column_name='id';