将SQL查询从MYSQL导入到Ms Access

时间:2013-11-29 21:33:33

标签: mysql sql ms-access

我需要创建sql语句以将现有MySQL数据库中的数据导入MsAccess。 有没有人对我能做到这一点的最好方法有任何想法?

这是我用来在MySQL中创建数据库的代码,只是为了给出表格等等。

 CREATE DATABASE IF NOT EXISTS horsedb;
 USE horsedb; CREATE TABLE `horse`.`horse` (
`HORSE_id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NULL,
`Colour` VARCHAR(45) NULL,
`Sire` INT NULL,
`Dam` INT NULL,
`Born` YEAR NULL,
`Trainer_id` INT NOT NULL, 
PRIMARY KEY (`HORSE_id`))
ENGINE = InnoDB;

USE horsedb; CREATE TABLE `horse`.`showsite` (  
`show_id` INT NOT NULL AUTO INCREMENT,  
`Name` VARCHAR(45) NULL,
`Address` VARCHAR(45) NULL,
PRIMARY KEY (`show_id`));

USE horsedb; CREATE TABLE `horse`.`judge` (  
`Judge_id` INT NOT NULL AUTO INCREMENT,  
`Name` VARCHAR(45) NULL,  
`Address` VARCHAR(45) NULL, 
PRIMARY KEY (`Judge_id`));

USE horsedb; CREATE TABLE `horse`.`event` (
`Event_id` INT NOT NULL AUTO INCREMENT,
`Show_id` INT NOT NULL, 
`Event_name` VARCHAR(45) NOT NULL,
`Judge_id` INT NOT NULL,
PRIMARY KEY (`Event_id`),
INDEX `show_id_idx` (`Show_id` ASC),
INDEX `judge_id_idx` (`Judge_id` ASC),
CONSTRAINT `show_id`
FOREIGN KEY (`Show_id`)  
REFERENCES `horsedb`.`showsite` (`Show_id`)  
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `judge_id`    
FOREIGN KEY (`Judge_id`)    
REFERENCES `horsedb`.`judge` (`Judge_id`)  
ON DELETE NO ACTION
ON UPDATE NO ACTION);

USE horsedb; CREATE TABLE `horse`.`entry` (
`Event_id` INT NOT NULL AUTO INCREMENT, 
`horse-id` INT NOT NULL, 
`Place` INT NULL, 
INDEX `horse_id_idx` (`Horse_id` ASC),
CONSTRAINT `horse_id`    
FOREIGN KEY (`Horse_id`)
REFERENCES `horsedb`.`horse` (`Horse_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

USE horsedb; CREATE TABLE `horse`.`prize` ( 
`Event_id` INT NOT NULL AUTO INCREMENT, 
`place` INT NULL,  
`money` INT NULL, 
 ));

USE horsedb; CREATE TABLE `horse`.`trainer` (  
`Trainer_id` INT NOT NULL AUTO INCREMENT,  
`Name` VARCHAR(45) NULL, 
PRIMARY KEY (`Trainer_id`));

1 个答案:

答案 0 :(得分:2)

将MySQL表转换为Access的最直接方法是安装MySQL ODBC驱动程序(MySQL Connector/ODBC),然后使用ODBC连接从MySQL导入(不链接)表。有关更详细的说明,请参阅:

Using Connector/ODBC with Microsoft Access