我已经在这个问题上工作了几个小时并且处于困境中。如果可以,请帮助我,我很感激......
我试图将一系列mysql语句转换为sql server 2008 express,用于一个小的wordpress数据库迁移项目。我不是MS SQL数据库中的专业人员......我已经转换了大部分语句,但需要帮助解决如何处理mySQL语句底部附近的表索引语句。如何将它们转换为SQL Server兼容语句?:
mySQL声明:
DROP TABLE IF EXISTS `wp_pollsip`;
CREATE TABLE IF NOT EXISTS `wp_pollsip` (
`pollip_id` int(10) NOT NULL AUTO_INCREMENT,
`pollip_qid` varchar(10) NOT NULL DEFAULT '',
`pollip_aid` varchar(10) NOT NULL DEFAULT '',
`pollip_ip` varchar(100) NOT NULL DEFAULT '',
`pollip_host` varchar(200) NOT NULL DEFAULT '',
`pollip_timestamp` varchar(20) NOT NULL DEFAULT '0000-00-00 00:00:00',
`pollip_user` tinytext NOT NULL,
`pollip_userid` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`pollip_id`),
KEY `pollip_ip` (`pollip_id`),
KEY `pollip_qid` (`pollip_qid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- Dumping data for table .wp_pollsip: ~5 rows (approximately)
DELETE FROM `wp_pollsip`;
/*!40000 ALTER TABLE `wp_pollsip` DISABLE KEYS */;
INSERT INTO `wp_pollsip` (`pollip_id`, `pollip_qid`, `pollip_aid`, `pollip_ip`, `pollip_host`, `pollip_timestamp`, `pollip_user`, `pollip_userid`) VALUES
(1, '1', '1', '11.11.11.11', 'isp-here', '1344836172', 'admin', 1),
(2, '2', '6', '11.11.11.11', 'isp-here', '1344836700', 'admin', 1),
(3, '3', '9', '11.11.11.11', 'isp-here', '1344963379', 'Guest', 0),
(4, '4', '12', '11.11.11.11', 'isp-here', '1345136711', 'admin', 1),
(5, '4', '14', '11.11.11.11', 'isp-here', '1345171584', 'Guest', 0);
/*!40000 ALTER TABLE `wp_pollsip` ENABLE KEYS */;
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
MS SQL,到目前为止:
-- Dumping structure for table .wp_pollsip
IF OBJECT_ID('wp_pollsip','U') IS NOT NULL DROP TABLE wp_pollsip;
CREATE TABLE wp_pollsip (
pollip_id bigint NOT NULL IDENTITY,
pollip_qid varchar(10) NOT NULL DEFAULT '',
pollip_aid varchar(10) NOT NULL DEFAULT '',
pollip_ip varchar(100) NOT NULL DEFAULT '',
pollip_host varchar(200) NOT NULL DEFAULT '',
pollip_timestamp varchar(20) NOT NULL DEFAULT '0000-00-00 00:00:00',
pollip_user char(256) NOT NULL,
pollip_userid int NOT NULL DEFAULT '0',
--PRIMARY KEY (pollip_id),
--KEY pollip_ip (pollip_id),
--KEY pollip_qid (pollip_qid)
);
-- Dumping data for table .wp_pollsip: ~5 rows (approximately)
DELETE FROM wp_pollsip;
/*!40000 ALTER TABLE wp_pollsip DISABLE KEYS */;
INSERT INTO wp_pollsip (pollip_qid, pollip_aid, pollip_ip, pollip_host, pollip_timestamp, pollip_user, pollip_userid) VALUES
('1', '1', '11.11.11.11', 'isp-here', '1344836172', 'admin', 1),
('2', '6', '11.11.11.11', 'isp-here', '1344836700', 'admin', 1),
('3', '9', '11.11.11.11', 'isp-here', '1344963379', 'Guest', 0),
('4', '12', '11.11.11.11', 'isp-here', '1345136711', 'admin', 1),
('4', '14', '11.11.11.11', 'isp-here', '1345171584', 'Guest', 0);
/*!40000 ALTER TABLE wp_pollsip ENABLE KEYS */;
我希望这是有道理的,谢谢。
答案 0 :(得分:1)
在MSSQL中,您通常会显式创建索引,但主键除外:
IF OBJECT_ID('wp_pollsip','U') IS NOT NULL DROP TABLE wp_pollsip;
CREATE TABLE wp_pollsip (
pollip_id bigint NOT NULL IDENTITY primary key,
pollip_qid varchar(10) NOT NULL DEFAULT '',
pollip_aid varchar(10) NOT NULL DEFAULT '',
pollip_ip varchar(100) NOT NULL DEFAULT '',
pollip_host varchar(200) NOT NULL DEFAULT '',
pollip_timestamp varchar(20) NOT NULL DEFAULT '0000-00-00 00:00:00',
pollip_user char(256) NOT NULL,
pollip_userid int NOT NULL DEFAULT '0',
);
create index idx_wp_pollsip_gid on wp_pollsip(pollip_gid);
您不需要在pollip_id上创建索引,因为它被声明为主键。