嘿伙计们我正在创建一个快速的mysql文件来创建一个包含一些表格的数据库。我似乎记得我可以一次创建数据库和表而不使用USE my_db吗?
这就是我现在正在使用的内容。
CREATE DATABASE IF NOT EXISTS `preferred_inspections`;
USE `preferred_inspections`;
DROP TABLE IF EXISTS `my_table1`;
CREATE TABLE `my_table1` (
`key` INT UNSIGNED AUTO_INCREMENT,
`role` VARCHAR(70),
`region` VARCHAR(70),
`inspection_type` VARCHAR(70),
`inspection_number` SMALLINT,
`customer_number` VARCHAR(70),
`report_date` DATE DEFAULT NULL,
PRIMARY KEY(key)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
DROP TABLE IF EXISTS `my_table2`;
CREATE TABLE `my_table2` (
`key` INT UNSIGNED AUTO_INCREMENT,
`role` VARCHAR(70),
`region` VARCHAR(70),
`inspection_type` VARCHAR(70),
`inspection_number` SMALLINT,
`customer_number` VARCHAR(70),
`report_date` DATE DEFAULT NULL,
PRIMARY KEY(key)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
我不能做这样的事吗?我似乎无法记住或找到一个例子......
DROP DATABASE IF EXISTS `preferred_inspections`;
CREATE DATABASE `preferred_inspections` (
CREATE TABLE `my_table1` (
`key` INT UNSIGNED AUTO_INCREMENT,
`role` VARCHAR(70),
`region` VARCHAR(70),
`inspection_type` VARCHAR(70),
`inspection_number` SMALLINT,
`customer_number` VARCHAR(70),
`report_date` DATE DEFAULT NULL,
PRIMARY KEY(key)
),
CREATE TABLE `my_table2` (
`key` INT UNSIGNED AUTO_INCREMENT,
`role` VARCHAR(70),
`region` VARCHAR(70),
`inspection_type` VARCHAR(70),
`inspection_number` SMALLINT,
`customer_number` VARCHAR(70),
`report_date` DATE DEFAULT NULL,
PRIMARY KEY(key)
)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
感谢Guys n'Gals
答案 0 :(得分:2)
使用:
CREATE TABLE `preferred_inspections`.`my_table1` (
.
.
.
);