Search code examples
mysqldatabasecreate-table

How to create a table in a particular database?


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?


Solution

  • 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, .... )