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

How to create a data Table by mysql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces mysql how to create a data table, the article is very detailed, has a certain reference value, interested friends must read it!

Establish the SQL general syntax for the data table:

CREATE TABLE table_name (column_name column_type)

We can create mysql data tables in two ways.

1. Create a table from the command prompt

Through the mysql > command window, you can easily create an MySQL data table using the SQL statement CREATE TABLE.

Example:

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 >

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 column primary keys. You can use multiple columns to define the primary key, separated by commas.

● ENGINE sets the storage engine and CHARSET sets the encoding.

Note: the MySQL command Terminator is a semicolon;. -> is a newline identifier. Do not copy it.

2. Use PHP script to create data table

We can use the mysqli_query () function of PHP to create a data table of an existing database.

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

The basic syntax of the mysqli_query () function:

Mysqli_query (connection,query,resultmode)

Code example:

3. View the data sheet

After the data table is established, you can view the structure of the table from the command prompt:

This is all about how mysql created the datasheet. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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