MySQL 如何在特定数据库中创建表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2749807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:56:43  来源:igfitidea点击:

How to create a table in a particular database?

mysqldatabasecreate-table

提问by user295515

The create database statement is:

创建数据库语句是:

CREATE TABLE table_name
(
    column_name1 data_type,
    column_name2 data_type,
    column_name3 data_type,
    ....
)

But I'm wondering how can I create a table in a specific database?

但我想知道如何在特定数据库中创建表?

回答by Dmitry Yudakov

You can specify the DB Name in the same query:

您可以在同一查询中指定数据库名称:

CREATE TABLE database_name.table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... )

CREATE TABLE database_name.table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... )

回答by Md Shariful Islam

You can try this query. Suppose the database name schoolmanagementsystem, table name student, and table columns name are student_id, student_first_name, and student_last_name.

你可以试试这个查询。假设数据库名schoolmanagementsystem,表名student和表列名的student_idstudent_first_namestudent_last_name

So you can create a table (student) in a particular database (schoolmanagementsystem) following this way.

因此,您可以按照这种方式student在特定数据库 ( schoolmanagementsystem) 中创建表 ( ) 。

CREATE TABLE schoolmanagementsystem.student
(
    student_id int(10) not null,
    student_first_name varchar(20) not null,
    student_last_name varchar(20)not null
);

回答by Bibek Gupta

You can create table inside a particular database as below:

您可以在特定数据库中创建表,如下所示:

CREATE TABLE database_name.table_name_();

CREATE TABLE library_database.book
(
    book_id int(10) not null,
    book_name varchar(20) not null,
    author_name varchar(20)not null
);

回答by Peter Kühne

Assuming that you have more than one database, in mysql, you can do SHOW DATABASESto view them all and then USEwith your db name to make it the current one. Running CREATE TABLEwill then create the table in that database.

假设您有多个数据库,在mysql中,您可以SHOW DATABASES查看所有数据库,然后USE使用您的数据库名称使其成为当前数据库。CREATE TABLE然后运行将在该数据库中创建表。

回答by mahesh

SELECT * FROM information_schema.TABLES where table_schema ='database_name' ORDER BY TABLES.CREATE_TIMEDESC

SELECT * FROM information_schema.TABLES where table_schema ='database_name' ORDER BY TABLESCREATE_TIME发展研究中心