如何在特定数据库中创建表?
创建数据库语句是:
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)
但我想知道如何在特定数据库中创建表?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以在同一查询中指定数据库名称:
CREATE TABLE database_name.table_name (column_name1 data_type,column_name2 data_type,column_name3 data_type, ....)
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, .... )
USE dbname;
http://dev.mysql .com/doc/refman/5.1/en/use.html
USE dbname;
http://dev.mysql.com/doc/refman/5.1/en/use.html
你可以尝试这个查询。
假设数据库名称
schoolmanagementsystem
、表名称student
和表列名称分别为student_id
、student_first_name
和学生姓氏
。因此,您可以按照这种方式在特定数据库(
schoolmanagementsystem
)中创建一个表(student
)。You can try this query.
Suppose the database name
schoolmanagementsystem
, table namestudent
, and table columns name arestudent_id
,student_first_name
, andstudent_last_name
.So you can create a table (
student
) in a particular database (schoolmanagementsystem
) following this way.您可以在特定数据库中创建表,如下所示:
You can create table inside a particular database as below:
假设您有多个数据库,在 mysql 中,您可以执行 SHOW DATABASES 来查看所有数据库,然后使用您的数据库名称使其成为当前数据库。运行
CREATE TABLE
将在该数据库中创建表。Assuming that you have more than one database, in mysql, you can do
SHOW DATABASES
to view them all and thenUSE
with your db name to make it the current one. RunningCREATE TABLE
will then create the table in that database.选择 *
FROM information_schema.TABLES 其中 table_schema ='database_name'
ORDER BY
TABLES
.CREATE_TIME
DESCSELECT *
FROM information_schema.TABLES where table_schema ='database_name'
ORDER BY
TABLES
.CREATE_TIME
DESC