如何从属于数据库"A“的表更新/插入数据到属于数据库"B”的表?
例如,我有一个名为ips的表,如下所示,属于数据库"A":
CREATE TABLE `ips` (
`id` int(10) unsigned NOT NULL DEFAULT '0',
`begin_ip_num` int(11) unsigned DEFAULT NULL,
`end_ip_num` int(11) unsigned DEFAULT NULL,
`iso` varchar(3) DEFAULT NULL,
`country` varchar(150) DEFAULT NULL
) ENGINE=InnoDB假设我有第二个表country属于数据库"B":
CREATE TABLE `country` (
`countryid` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`ordering` smallint(5) unsigned NOT NULL DEFAULT '0',
`iso` char(2) NOT NULL,
PRIMARY KEY (`countryid`)
) ENGINE=InnoDB注意:这两个数据库在同一台服务器上
发布于 2013-08-29 19:38:58
您必须在表名前面加上DB/模式名。大概是这样的:
INSERT INTO `database B`.`country` (columns)
SELECT columns FROM `database A`.`ips`;当然,您必须根据需要将columns替换为所需的列名和/或表达式。
发布于 2013-08-29 19:38:44
在SQLServer中是这样的;
insert x select * from otherdatabase.owner.table
其可以被扩展以选择列等。
在Oracle中,您可能需要在它们之间建立数据库链接。THat对我来说已经是很久以前的事了;-)
https://stackoverflow.com/questions/18509902
复制相似问题