MySQL代码架构生成的代码什么都不做?

时间:2011-09-11 17:49:41

标签: mysql sql database

我正在使用MySQL来设计数据库,我正在使用工作台上的“SQL Create Script”选项导出用于生成数据库的代码。但是,当我运行代码并使用SHOW TABLES时,我得到null,这可能意味着数据库中没有创建表。这是生成的代码(它很长但是因为它是自动生成的,所以错误可能来自我导出它时的设置。)

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `travel_agency` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `travel_agency` ;

-- -----------------------------------------------------
-- Table `travel_agency`.`Region`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Region` (
  `region_name` VARCHAR(45) NOT NULL ,
  `languages` VARCHAR(100) NOT NULL ,
  PRIMARY KEY (`region_name`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Country`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Country` (
  `country_name` VARCHAR(15) NOT NULL ,
  `Region_region_name` VARCHAR(45) NOT NULL ,
  `currency` CHAR(20) NOT NULL ,
  PRIMARY KEY (`country_name`, `Region_region_name`) ,
  INDEX `fk_Country_Region1` (`Region_region_name` ASC) ,
  CONSTRAINT `fk_Country_Region1`
    FOREIGN KEY (`Region_region_name` )
    REFERENCES `travel_agency`.`Region` (`region_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Transport`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Transport` (
  `Country_country_name` VARCHAR(15) NOT NULL ,
  `cost_estimate` DECIMAL(8,2) NOT NULL ,
  `transport_deals` BLOB NOT NULL ,
  `transport_rating` CHAR(1) NOT NULL ,
  PRIMARY KEY (`Country_country_name`) ,
  CONSTRAINT `fk_Transport_Country`
    FOREIGN KEY (`Country_country_name` )
    REFERENCES `travel_agency`.`Country` (`country_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Resort`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Resort` (
  `resort_name` VARCHAR(50) NOT NULL ,
  `city` VARCHAR(50) NOT NULL ,
  `Country_country_name` VARCHAR(15) NOT NULL ,
  `resort_type` CHAR(20) NOT NULL ,
  INDEX `fk_Resort_Country1` (`Country_country_name` ASC) ,
  PRIMARY KEY (`resort_name`, `city`) ,
  CONSTRAINT `fk_Resort_Country1`
    FOREIGN KEY (`Country_country_name` )
    REFERENCES `travel_agency`.`Country` (`country_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Hotel`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Hotel` (
  `hotel_name` CHAR NOT NULL ,
  `rating` CHAR(1) NOT NULL ,
  `address1` CHAR(50) NOT NULL ,
  `address2` CHAR(50) NOT NULL ,
  `postcode` CHAR(10) NOT NULL ,
  `telephone` CHAR(20) NOT NULL ,
  `Resort_resort_name` VARCHAR(50) NOT NULL ,
  PRIMARY KEY (`hotel_name`) ,
  INDEX `fk_Hotel_Resort1` (`Resort_resort_name` ASC) ,
  CONSTRAINT `fk_Hotel_Resort1`
    FOREIGN KEY (`Resort_resort_name` )
    REFERENCES `travel_agency`.`Resort` (`resort_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Room`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Room` (
  `room_num` INT NOT NULL ,
  `room_type` CHAR(10) NOT NULL ,
  `Hotel_hotel_name` CHAR NOT NULL ,
  `minibar` BIT NOT NULL ,
  `tv` BIT NOT NULL ,
  `smoking_permitted` BIT NOT NULL ,
  INDEX `fk_Room_Hotel1` (`Hotel_hotel_name` ASC) ,
  PRIMARY KEY (`room_num`, `room_type`) ,
  CONSTRAINT `fk_Room_Hotel1`
    FOREIGN KEY (`Hotel_hotel_name` )
    REFERENCES `travel_agency`.`Hotel` (`hotel_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Guest`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Guest` (
  `guest_id` INT NOT NULL ,
  `firstname` VARCHAR(20) NOT NULL ,
  `surname` VARCHAR(20) NOT NULL ,
  `mobilephone` CHAR(20) NOT NULL ,
  PRIMARY KEY (`guest_id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Bookings`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Bookings` (
  `Guest_guest_id` INT NOT NULL ,
  `Hotel_hotel_name` CHAR NOT NULL ,
  `guest_count` INT NOT NULL ,
  PRIMARY KEY (`Guest_guest_id`, `Hotel_hotel_name`) ,
  INDEX `fk_Booking_Guest1` (`Guest_guest_id` ASC) ,
  INDEX `fk_Booking_Hotel1` (`Hotel_hotel_name` ASC) ,
  CONSTRAINT `fk_Booking_Guest1`
    FOREIGN KEY (`Guest_guest_id` )
    REFERENCES `travel_agency`.`Guest` (`guest_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Booking_Hotel1`
    FOREIGN KEY (`Hotel_hotel_name` )
    REFERENCES `travel_agency`.`Hotel` (`hotel_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`HotelFacilities`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`HotelFacilities` (
  `Hotel_hotel_name` CHAR NOT NULL ,
  `internet_access` BIT NOT NULL ,
  `hotel_restaurant` BIT NOT NULL ,
  `games_room` BIT NOT NULL ,
  `bar` BIT NOT NULL ,
  `evening_shows` BIT NOT NULL ,
  `massage_parlour` BIT NOT NULL ,
  `misc_details` BLOB NOT NULL ,
  PRIMARY KEY (`Hotel_hotel_name`) ,
  CONSTRAINT `fk_HotelFacilities_Hotel1`
    FOREIGN KEY (`Hotel_hotel_name` )
    REFERENCES `travel_agency`.`Hotel` (`hotel_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Attractions`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Attractions` (
  `Region_region_name` VARCHAR(45) NOT NULL ,
  `dirt_mountains` BIT NOT NULL ,
  `beaches` BIT NOT NULL ,
  `casinos` BIT NOT NULL ,
  `safari` BIT NOT NULL ,
  `snow_mountains` BIT NOT NULL ,
  `misc_details` BLOB NOT NULL ,
  PRIMARY KEY (`Region_region_name`) ,
  CONSTRAINT `fk_Attractions_Region1`
    FOREIGN KEY (`Region_region_name` )
    REFERENCES `travel_agency`.`Region` (`region_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `travel_agency`.`Rate`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `travel_agency`.`Rate` (
  `Hotel_hotel_name` CHAR NOT NULL ,
  `Room_room_num` INT NOT NULL ,
  `Room_room_type` CHAR(10) NOT NULL ,
  `first_quarter` DECIMAL(20,2) NOT NULL ,
  `second_quarter` DECIMAL(20,2) NOT NULL ,
  `third_quarter` DECIMAL(20,2) NOT NULL ,
  `fourth_quarter` DECIMAL(20,2) NOT NULL ,
  `discount_information` BLOB NOT NULL ,
  PRIMARY KEY (`Hotel_hotel_name`, `Room_room_num`, `Room_room_type`) ,
  INDEX `fk_Rate_Room1` (`Room_room_num` ASC, `Room_room_type` ASC) ,
  CONSTRAINT `fk_Rate_Hotel1`
    FOREIGN KEY (`Hotel_hotel_name` )
    REFERENCES `travel_agency`.`Hotel` (`hotel_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Rate_Room1`
    FOREIGN KEY (`Room_room_num` , `Room_room_type` )
    REFERENCES `travel_agency`.`Room` (`room_num` , `room_type` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

我正在使用sql命令行客户端并放置代码,但它不起作用。

1 个答案:

答案 0 :(得分:0)

因为您使用命令行客户端作为数据库。这只会使您的电脑功能作为一个数据库,但并不具备专业数据库所具有的所有功能。而MySQL workbench旨在为数据库导出更专业的代码。

既然你正在使用命令行客户端我假设这是练习或某种类型的家庭作业?无论哪种方式,这是代码在命令行客户端中的工作方式。试试这个。

CREATE TABLE Region 
(
 region_name VARCHAR(45) NOT NULL ,
 languages VARCHAR(100) NOT NULL ,
 PRIMARY KEY (region_name) 
 );

CREATE TABLE Country
(
 country_name VARCHAR(15) NOT NULL ,
 Region_region_name VARCHAR(45) NOT NULL ,
 currency CHAR(20) NOT NULL ,
 PRIMARY KEY (country_name, Region_region_name) ,
 CONSTRAINT fk_Country_Region1
  FOREIGN KEY (Region_region_name )
  REFERENCES Region (region_name )
    );

CREATE TABLE Transport (
 Country_country_name VARCHAR(15) NOT NULL ,
 cost_estimate DECIMAL(8,2) NOT NULL ,
 transport_deals CHAR(100) NULL ,
 transport_rating CHAR(20) NOT NULL ,
 PRIMARY KEY (Country_country_name) ,
 CONSTRAINT fk_Transport_Country
  FOREIGN KEY (Country_country_name)
  REFERENCES Country (country_name )
    );

CREATE TABLE Resort (
 resort_name VARCHAR(50) NOT NULL ,
 Country_country_name VARCHAR(15) NOT NULL ,
 resort_type CHAR(20) NOT NULL ,
 PRIMARY KEY (resort_name) ,
 CONSTRAINT fk_Resort_Country1
  FOREIGN KEY (Country_country_name)
  REFERENCES Country (country_name)
);

CREATE TABLE Hotel (
 hotel_name CHAR(20) NOT NULL ,
 rating CHAR NOT NULL ,
 address1 CHAR(50) NOT NULL ,
 address2 CHAR(50) NOT NULL ,
 postcode CHAR(10) NOT NULL ,
 telephone CHAR(20) NOT NULL ,
 Resort_resort_name VARCHAR(50) NOT NULL ,
 PRIMARY KEY (hotel_name) ,
 CONSTRAINT fk_Hotel_Resort1
  FOREIGN KEY (Resort_resort_name)
  REFERENCES Resort (resort_name)
);


CREATE TABLE Room (
 room_num INT NOT NULL ,
 room_type CHAR(10) NOT NULL ,
 Hotel_hotel_name CHAR(20) NOT NULL ,
 minibar BOOLEAN NOT NULL ,
 tv BOOLEAN NOT NULL ,
 smoking_permitted BOOLEAN NOT NULL ,
 PRIMARY KEY (room_num) ,
 CONSTRAINT fk_Room_Hotel1
  FOREIGN KEY (Hotel_hotel_name)
  REFERENCES Hotel (hotel_name)
    );

CREATE TABLE Guest (
 guest_id INT NOT NULL ,
 firstname VARCHAR(20) NOT NULL ,
 surname VARCHAR(20) NOT NULL ,
 mobilephone CHAR(20) NOT NULL ,
 PRIMARY KEY (guest_id) 
 );

CREATE TABLE Bookings (
 Guest_guest_id INT NOT NULL ,
 Hotel_hotel_name CHAR(20) NOT NULL ,
 guest_count INT NOT NULL ,
 PRIMARY KEY (Guest_guest_id, Hotel_hotel_name) ,
 CONSTRAINT fk_Booking_Guest1
  FOREIGN KEY (Guest_guest_id)
  REFERENCES Guest (guest_id),
 CONSTRAINT fk_Booking_Hotel1
  FOREIGN KEY (Hotel_hotel_name)
  REFERENCES Hotel (hotel_name)
);

CREATE TABLE HotelFacilities (
 Hotel_hotel_name CHAR(20) NOT NULL ,
 internet_access BOOLEAN NOT NULL ,
 hotel_restaurant BOOLEAN NOT NULL ,
 games_room BOOLEAN NOT NULL ,
 bar BOOLEAN NOT NULL ,
 evening_shows BOOLEAN NOT NULL ,
 massage_parlour BOOLEAN NOT NULL ,
 misc_details CHAR(100) NULL ,
 PRIMARY KEY (Hotel_hotel_name) ,
 CONSTRAINT fk_HotelFacilities_Hotel1
  FOREIGN KEY (Hotel_hotel_name)
  REFERENCES Hotel (hotel_name)
    );

CREATE TABLE Attractions (
 Region_region_name VARCHAR(45) NOT NULL ,
 dirt_mountains BOOLEAN NOT NULL ,
 beaches BOOLEAN NOT NULL ,
 casinos BOOLEAN NOT NULL ,
 safari BOOLEAN NOT NULL ,
 snow_mountains BOOLEAN NOT NULL ,
 misc_details CHAR(100) NULL ,
 PRIMARY KEY (Region_region_name) ,
 CONSTRAINT fk_Attractions_Region1
  FOREIGN KEY (Region_region_name )
  REFERENCES Region (region_name )
  );

CREATE TABLE Rate (
 Hotel_hotel_name CHAR(20) NOT NULL ,
 Room_room_num INT NOT NULL ,
 first_quarter DECIMAL(10,2) NOT NULL ,
 second_quarter DECIMAL(10,2) NOT NULL ,
 third_quarter DECIMAL(10,2) NOT NULL ,
 fourth_quarter DECIMAL(10,2) NOT NULL ,
 discount_information CHAR(100) NULL ,
 PRIMARY KEY (Hotel_hotel_name, Room_room_num) ,
 CONSTRAINT fk_Rate_Hotel1
  FOREIGN KEY (Hotel_hotel_name )
  REFERENCES Hotel (hotel_name ),
 CONSTRAINT fk_Rate_Room1
  FOREIGN KEY (Room_room_num)
  REFERENCES Room (room_num)
  );