有沒有辦法使現有的txt字段唯一(不要接受重複的值)?如何讓一個mysql字段獨一無二?
場:POST_TITLE
類型:文本
校對:utf8_unicode_ci
空:辛
默認值:NULL
,如果有人試圖插入與現有職務任職,會發生什麼打算?
這可能會影響我的網站的某些功能嗎?
結構
CREATE TABLE IF NOT EXISTS `hotaru_posts` (
`post_id` int(20) NOT NULL AUTO_INCREMENT,
`post_archived` enum('Y','N') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'N',
`post_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`post_author` int(20) NOT NULL DEFAULT '0',
`post_date` timestamp NULL DEFAULT NULL,
`post_pub_date` timestamp NULL DEFAULT NULL,
`post_status` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'processing',
`post_type` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`post_category` int(20) NOT NULL DEFAULT '1',
`post_tags` text COLLATE utf8_unicode_ci,
`post_title` text COLLATE utf8_unicode_ci,
`post_orig_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`post_domain` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`post_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`post_content` text COLLATE utf8_unicode_ci,
`post_votes_up` smallint(11) NOT NULL DEFAULT '0',
`post_votes_down` smallint(11) NOT NULL DEFAULT '0',
`post_comments` enum('open','closed') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'open',
`post_media` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'text',
`post_img` text COLLATE utf8_unicode_ci NOT NULL,
`post_subscribe` tinyint(1) NOT NULL DEFAULT '0',
`post_updateby` int(20) NOT NULL DEFAULT '0',
`post_views` int(20) NOT NULL DEFAULT '0',
`post_last_viewer_ip` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '111.111.111.111',
PRIMARY KEY (`post_id`),
KEY `post_archived` (`post_archived`),
KEY `post_status` (`post_status`),
KEY `post_type` (`post_type`),
FULLTEXT KEY `post_title` (`post_title`,`post_domain`,`post_url`,`post_content`,`post_tags`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Story Posts' AUTO_INCREMENT=38275 ;
可能重複[MySQL的 - 做一個領域獨樹一幟]認爲沒有幫助(http://stackoverflow.com/questions/5038040/mysql-make-a-field-unique) – bernie 2012-03-02 03:33:56
,所有查詢都給予同樣的錯誤#1170 - 沒有密鑰長度的密鑰規範中使用的BLOB/TEXT列'post_title' – 2012-03-02 03:56:49
不要求帖子標題是唯一的,它不是必需的,帖子ID是唯一的,所以當有人在任何帖子上投票時,您將更新該行基於post_id,所以它不會產生問題 – 2012-03-02 05:19:31