gpt4 book ai didi

mysql - 一次创建数据库和表?

转载 作者:行者123 更新时间:2023-11-29 08:58:46 25 4
gpt4 key购买 nike

嘿伙计们,我正在创建一个快速 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;

谢谢大家

最佳答案

用途:

CREATE TABLE `preferred_inspections`.`my_table1` (
.
.
.
);

关于mysql - 一次创建数据库和表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9217333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com