Mysql method of creating a data table: Use the general SQL syntax [CREATE TABLE table_name (column_name column_type);] to create it successfully.
#The operating environment of this article: windows10 system, mysql 5.7, thinkpad t480 computer.
The following is the general SQL syntax for creating a MySQL data table:
CREATE TABLE table_name (column_name column_type);
In the following example we will create a data table tbl in the RUNOOB database:
CREATE TABLE IF NOT EXISTS `tbl`( `id` INT UNSIGNED AUTO_INCREMENT, `title` VARCHAR(100) NOT NULL, `author` VARCHAR(40) NOT NULL, `submission_date` DATE, PRIMARY KEY ( `id` ))ENGINE=InnoDB DEFAULT CHARSET=utf8;
Analysis:
If you don’t want the field to be NULL, you can set the attribute of the field to NOT NULL. If the data entered in this field is NULL when operating the database, an error will be reported.
AUTO_INCREMENT is defined as an auto-incrementing attribute, generally used for primary keys, and the value will automatically increase by 1.
PRIMARY KEY keyword is used to define the column as the primary key. You can define a primary key using multiple columns, separated by commas.
ENGINE sets the storage engine and CHARSET sets the encoding.
Learning recommendation: mysql tutorial
The above is the detailed content of How to create a data table in mysql database. For more information, please follow other related articles on the PHP Chinese website!