Home > Database > Mysql Tutorial > How to create a table in mysql

How to create a table in mysql

PHPz
Release: 2023-05-29 09:52:05
forward
4357 people have browsed it

1. The syntax for creating a data table in mysql

CREATE TABLE table_name (column_name column_type);
Copy after login

It is very easy to create a MySQL table at the mysql> prompt. Use the SQL command CREATE TABLE to create a table.

Before creating the table, you need to use the use databasename command to select the database.

2. Create mysql data table

Example:

root@host# mysql -u root -p
Enter password:
mysql> use TUTORIALS;
Database changed
mysql> CREATE TABLE tutorials_tbl(
   -> tutorial_id INT NOT NULL AUTO_INCREMENT,
   -> tutorial_title VARCHAR(100) NOT NULL,
   -> tutorial_author VARCHAR(40) NOT NULL,
   -> submission_date DATE,
   -> PRIMARY KEY ( tutorial_id )
   -> );
Query OK, 0 rows affected (0.16 sec)
mysql>
Copy after login

The above is the detailed content of How to create a table in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template