Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Instructions for MySQL to create a data table

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "MySQL create data table instructions", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "MySQL create data table instructions"!

MySQL creates a data table

The following information is required to create an MySQL data table:

Table name

Table field name

Define each table field

Grammar

The following is the general SQL syntax for creating MySQL data tables:

CREATE TABLE table_name (column_name column_type)

In the following example, we will create the data table runoob_tbl in the RUNOOB database:

CREATE TABLE IF NOT EXISTS `runoob_ tbl` (`runoob_ id` INT UNSIGNED 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

Instance resolution:

If you do not want the field to be NULL, you can set the property of the field to NOT NULL. If you enter the data of the field as NULL when operating the database, you will report an error.

The AUTO_INCREMENT definition is listed as a self-increasing attribute, which is generally used for primary keys, and the value is automatically incremented by 1.

The PRIMARY KEY keyword is used to define the column primary key. You can use multiple columns to define the primary key, separated by commas.

ENGINE sets the storage engine and CHARSET sets the encoding.

Create a table from the command prompt

You can easily create an MySQL data table through the mysql > command window. You can use the SQL statement CREATE TABLE to create a data table.

Example

The following is the creation of a datasheet runoob_tbl instance:

Root@host# mysql-u root-pEnter password:*mysql > use RUNOOB;Database changedmysql > CREATE TABLE runoob_tbl (- > runoob_id INT NOT NULL AUTO_INCREMENT,-> runoob_title VARCHAR (100th) NOT NULL,-> runoob_author VARCHAR (40) NOT NULL,-> submission_date DATE,-> PRIMARY KEY (runoob_id)->) ENGINE=InnoDB DEFAULT CHARSET=utf8;Query OK, 0 rows affected (0.16 sec) mysql >

Note: the MySQL command Terminator is a semicolon (;).

Create a datasheet using a PHP script

You can use the mysqli_query () function of PHP to create data tables in an existing database.

This function takes two arguments and returns TRUE on successful execution, or FALSE otherwise.

Syntax mysqli_query (connection,query,resultmode); parameter description connection is required. Specifies the MySQL connection to be used. Query is required, specifying the query string. Resultmode

Optional. A constant. It can be any of the following values:

MYSQLI_USE_RESULT (use this if you need to retrieve a large amount of data)

MYSQLI_STORE_RESULT (default)

Example

The following example uses a PHP script to create a data table:

Create a datasheet

After successful execution, you can view the table structure from the command line:

Thank you for your reading, the above is the content of the "MySQL data table instructions", after the study of this article, I believe you have a deeper understanding of the MySQL data table instructions, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report