Reputation: 897
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?
Upvotes: 50
Views: 126090
Reputation: 31
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
);
Upvotes: 3
Reputation: 157
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
.
So you can create a table (student
) in a particular database (schoolmanagementsystem
) following this way.
CREATE TABLE schoolmanagementsystem.student
(
student_id int(10) not null,
student_first_name varchar(20) not null,
student_last_name varchar(20)not null
);
Upvotes: 5
Reputation: 1
SELECT *
FROM information_schema.TABLES where table_schema ='database_name'
ORDER BY TABLES
.CREATE_TIME
DESC
Upvotes: -1
Reputation: 15734
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, .... )
Upvotes: 82
Reputation: 3274
Assuming that you have more than one database, in mysql, you can do SHOW DATABASES
to view them all and then USE
with your db name to make it the current one. Running CREATE TABLE
will then create the table in that database.
Upvotes: 0