sql - 使用单个sql命令创建多个表

标签 sql database mysql

我在这里和谷歌上搜索了这个,但令人惊讶的是找不到答案。我试图创建提交给 mysql 的语法,这将创建具有相同列的多个表,但它返回了一个错误。你能指出我的语法有什么问题吗?或者这是否可能?

 CREATE TABLE news, life
 (
 id int PRIMARY KEY AUTO_INCREMENT ,
 name varchar( 30 ) ,
 email varchar( 50 ) ,
 COMMENT text,
 datetime datetime,
 ip varchar( 20 )
 ) 

最佳答案

你在 mysql 中,所以你可以使用 CREATE TABLE 命令的 LIKE 子句;这样您还将获得复制的列属性和索引,例如

CREATE TABLE new_tbl LIKE orig_tbl;

参见 http://dev.mysql.com/doc/refman/5.1/en/create-table.html

Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table: CREATE TABLE new_tbl LIKE orig_tbl; The copy is created using the same version of the table storage format as the original table. The SELECT privilege is required on the original table. LIKE works only for base tables, not for views. CREATE TABLE ... LIKE does not preserve any DATA DIRECTORY or INDEX DIRECTORY table options that were specified for the original table, or any foreign key definitions.

关于sql - 使用单个sql命令创建多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2123897/

相关文章:

mysql - MySQL 中大整数的逻辑运算

php - 同步: how get a blob from MySql and save it in another MySql with php

database - 如何将清理后的原始数据存储在数据库中?

database - Postgresql 函数中的列命名

mysql - 如何在MySQL中获取具有相同元素数量的文件名?

mysql - 查询 MySQL 表

sql - 使用动态 WHERE 子句的慢查询

PHPBB3 - 从插入语句中获取行

SQL Server : group_by select active dates

mysql - SQL 错误 (1215) : Cannot add foreign key constraint