Home >Database >Mysql Tutorial >What is the command to create a table in mysql?
The mysql create table command is [CREATE TABLE table_name (column_name column_type);], where the parameters include the table name, table field name, and each defined table field.
#How to create a MySQL data table? The following article will introduce to you how to create a data table through the command prompt. I hope it will be helpful to you.
The following information is required to create a MySQL data table:
● Table name
● Table field name
● Define each table field
Basic syntax
The following is the general SQL syntax for creating MySQL data tables:
CREATE TABLE table_name (column_name column_type);
Example: Create a table through the command prompt
MySQL data tables can be easily created through the mysql> command window. You can create a data table using the SQL statement CREATE TABLE.
1. First connect to the mysql server and enter the password
root@host# mysql -u root -p Enter password:*******
2. Enter the database RUNOOB
use RUNOOB;
3. Create the table
mysql> CREATE TABLE runoob_tbl( -> runoob_id INT NOT NULL AUTO_INCREMENT, -> runoob_title VARCHAR(100) NOT NULL, -> runoob_author VARCHAR(40) NOT NULL, -> submission_date DATE, -> PRIMARY KEY ( runoob_id ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Output:
Query OK, 0 rows affected (0.16 sec)
indicates that the data table is created successfully.
Note: MySQL command terminator is semicolon;.
Note: -> is a newline identifier, do not copy it.
Example analysis:
●If you don’t want the field to be NULL, you can set the attribute of the field to NOT NULL. When operating the database, if the data entered in this field is NULL, an error will be reported.
● AUTO_INCREMENT is defined as a self-increasing attribute, generally used for primary keys, and the value will automatically increase by 1.
● The PRIMARY KEY keyword is used to define a column as the primary key. You can define a primary key using multiple columns, separated by commas.
● ENGINE sets the storage engine, CHARSET sets the encoding.
We can use the command to view the command line view table structure
The above is the detailed content of What is the command to create a table in mysql?. For more information, please follow other related articles on the PHP Chinese website!