Get the App
SLTechnology News&Howtos  ›  Database  › 

How to create data Table in MySql

Shulou Source: shulou.com Published: 2022-05-31 20:37:46 09月22日 Update

It is believed that many inexperienced people have no idea about how to create a data table in MySql. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

After the database is created successfully, you need to create a data table. by creating a data table, you mean creating a new table in an existing database. It is important to note that before manipulating the data table, you should use the "USE database name" to specify which database the operation is in, otherwise a "No database selected" error will be thrown. The basic syntax format for creating a data table is as follows:

CREATE TABLE table name

(

Field name 1, data type [integrity constraint]

Field name 2, data type [integrity constraint]

...

Field name n, data type [integrity constraint]

)

In the above syntax format, "table name" refers to the name of the data table created, "field name" refers to the column name of the data table, and "integrity constraint" refers to some special constraints of the field. For example, create a table TB _ grade that stores student scores.

Field name data type remarks

Number of idINT (11) student

Name of nameVARCHR (20) student

The grades of gredeFLOAT students

To create the data table as above, we need to first create a grade_db database with the following SQL statement:

Create database grade_db

Through the SHOW DATABASES; command, we can see that "grade_db" has often been successful.

Select the database you created, and the SQL statement is as follows:

Use grade_db

The SQL statement to create the data table is as follows:

Create table tb_grade

(

Id int (11)

Name varchar (20)

Grade flaot

)

After reading the above, have you mastered the method of how to create data tables in MySql? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Data datasheet field database condition student integrity type statement success content name score method is in more format syntax problem special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker MySQL Huawei Apple