mysql怎么查某表主键,查询数据库表主键
mysql 怎么查询某个表最后一个主键的值?
知道字段名吗?
武宁ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!
第一,查出主键名,
第二,使用主键来select.
SELECT
t.TABLE_NAME,
t.CONSTRAINT_TYPE,
c.COLUMN_NAME,
c.ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
WHERE
t.TABLE_NAME = c.TABLE_NAME
AND t.TABLE_SCHEMA = 'test'
AND t.CONSTRAINT_TYPE = 'PRIMARY KEY';
MYSQL查询表的主键
SELECT
t.TABLE_NAME,
t.CONSTRAINT_TYPE,
c.COLUMN_NAME,
c.ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
WHERE
t.TABLE_NAME = c.TABLE_NAME
AND t.TABLE_SCHEMA = 'test'
AND t.CONSTRAINT_TYPE = 'PRIMARY KEY';
测试执行结果如下:
mysql SELECT
- t.TABLE_NAME,
- t.CONSTRAINT_TYPE,
- c.COLUMN_NAME,
- c.ORDINAL_POSITION
- FROM
- INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
- INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
- WHERE
- t.TABLE_NAME = c.TABLE_NAME
- AND t.TABLE_SCHEMA = 'test'
- AND t.CONSTRAINT_TYPE = 'PRIMARY KEY'
- LIMIT 3;
+------------+-----------------+-------------+------------------+
| TABLE_NAME | CONSTRAINT_TYPE | COLUMN_NAME | ORDINAL_POSITION |
+------------+-----------------+-------------+------------------+
| mr_dept | PRIMARY KEY | dept_id | 1 |
| order | PRIMARY KEY | id | 1 |
| tab | PRIMARY KEY | id | 1 |
+------------+-----------------+-------------+------------------+
3 rows in set (0.06 sec)
mysql 主键查询是怎么查的
SELECT
t.TABLE_NAME,
t.CONSTRAINT_TYPE,
c.COLUMN_NAME,
c.ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
WHERE
t.TABLE_NAME = c.TABLE_NAME
AND t.TABLE_SCHEMA = 'test'
AND t.CONSTRAINT_TYPE = 'PRIMARY KEY';
测试执行结果如下:
mysql SELECT
- t.TABLE_NAME,
- t.CONSTRAINT_TYPE,
- c.COLUMN_NAME,
- c.ORDINAL_POSITION
- FROM
- INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,
- INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c
- WHERE
- t.TABLE_NAME = c.TABLE_NAME
- AND t.TABLE_SCHEMA = 'test'
- AND t.CONSTRAINT_TYPE = 'PRIMARY KEY'
- LIMIT 3;
+------------+-----------------+-------------+------------------+
| TABLE_NAME | CONSTRAINT_TYPE | COLUMN_NAME | ORDINAL_POSITION |
+------------+-----------------+-------------+------------------+
| mr_dept | PRIMARY KEY | dept_id | 1 |
| order | PRIMARY KEY | id | 1 |
| tab | PRIMARY KEY | id | 1 |
+------------+-----------------+-------------+------------------+
3 rows in set (0.06 sec)
怎么看MYSQL表的主键
楼主用的什么样的客户端程序?不同的客户端程序查看的方式可能不一样。我用Navicat。选择表后点右键---选择设计表,在字段后面有个黄色的钥匙,那个字段就是主键。
尽管客户端不同,但查看应该都是在设计表中。
如何查看mysql中一张表的主键、字段是否为空等信息
用命令:DESCRIBE 数据库名.表名;
结果:
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| product_id | int(11) | NO | PRI | NULL | |
| name | varchar(255) | NO | MUL | NULL | |
| description | text | NO | | NULL | |
| meta_title | varchar(255) | NO | | NULL | |
+------------------+--------------+------+-----+---------+-------+
当前标题:mysql怎么查某表主键,查询数据库表主键
转载源于:http://scyanting.com/article/dsejopg.html