Mysql Select记录,其中PRIMARY键= x [英] Mysql Select record where PRIMARY key = x
问题描述
我的mysql表中有一个主键,该键由三列组成.
I have a primary key in my mysql table which is comprised of three columns.
CREATE TABLE IF NOT EXISTS `bb_bulletin` (
`OfficeCode` int(5) NOT NULL,
`IssuerId` int(11) NOT NULL,
`BulletinDtm` datetime NOT NULL,
`CategoryCode` varchar(4) NOT NULL,
`Title` varchar(255) NOT NULL,
`Content` text NOT NULL,
PRIMARY KEY (`OfficeCode`,`IssuerId`,`BulletinDtm`),
UNIQUE KEY `U_IssuerId` (`IssuerId`,`OfficeCode`,`BulletinDtm`),
UNIQUE KEY `U_CategoryCode` (`CategoryCode`,`OfficeCode`,`IssuerId`,`BulletinDtm`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
是否有一种速记方法可以为给定的主键值选择一条记录.
Is there a shorthand method to select a record for a given value of the primary key.
我尝试过.
SELECT * FROM `bb_bulletin` WHERE PRIMARY = '20001-1-2011-01-07 14:04:40'
代替了长期使用的方法
SELECT * From bb_bulletin WHERE OfficeCode = 20001 AND IssuerId = 1 AND BulletinDtm = 2011-01-07 14:04:40
在表中处理php和复合键时的标准是什么. 注意:我不想在表中添加自动递增键以解决此问题.如果不可能,那么我将在URL中传递三个约束.
What is the standard when dealing php and composite keys in your table. Note: I don't want to add autoincrementing keys to my tables in order to solve this. If it is not possible then I will just pass the three constraints in my url.
推荐答案
我看到了您的问题的两个部分.第一部分是关于引用复合值.我不确定MySQL是否支持此功能,但这将是SQL标准的方式:
I see two parts to your question. The first part is about referencing a composite value. I'm not sure whether MySQL support this, but it would be the SQL standard way of doing this:
SELECT * FROM bb_bulletin WHERE (OfficeCode, IssuerId, BulletinDtm) = (20001, 1, '2011-01-07 14:04:40');
另一部分使用缩写语法引用主键列.我不知道有这种可能性.
The other part is referring to the primary key columns using an abbreviated syntax. I don't know of any such possibility.
这篇关于Mysql Select记录,其中PRIMARY键= x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!