如何判断表的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 数据操作的一个问题 apple_8180大侠,请您帮帮小妹解决这个问题吧 查询出生日期为最近7天的sql MYSQL查询死机问题!急!!!在线等! mysql 的dec的字段如何自动增加序列呢?当插入新的数据时候 mysql导出问题!!!!!!! 请问有什么好的mysql服务器程序下载? 可否使用win2000pro+asp+MySQL? 数据库mysql,后端node做的报表统计问题 mysqldump 如何备份数据库,某几个表备份全部,一个表根据条件备份 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';