Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql sets the primary key of data table and the method of self-growth

Shulou Source: shulou.com Published: 2022-06-01 02:27:38 11月12日 Update

This article is about how mysql sets the primary key of a data table and how to grow itself. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Mysql sets the primary key of the data table and the method of self-growth: first start MySQL, open navicat to establish a new table; then add fields and types; then execute relevant statements to insert data; finally, select the field and tick before the Auto Increment below for self-growth.

Mysql sets the primary key and self-growing method of the data table:

1. Start MySQL, open navicat, create a new database aaa, right-click Tables, select new table, and create a new table.

2. Add field xsid with type int, and add field xsname with type vachar. As shown in the figure, select the field xsid and set it as the primary key by clicking Primary Key, or the location of 2 in the figure. Save the table with the name xstable.

3. Open the table xstable, create a new query, and enter the sql statement in the diagram. After successful execution, a piece of data is inserted into the table.

4. Set the xsid value in sql to empty, and the first execution of the statement can be successful. Xsid stores 0 by default, and an error will be reported when it is executed the second time, as shown in the figure. You can see that if the specific value of xsid cannot be set, it cannot be executed successfully.

5. Open the design interface of table xstable, select the xsid field, and tick the Auto Increment below, that is, select automatic growth.

6. On the query page, if you execute the sql statement with empty xsid again, it will be executed successfully and can be executed multiple times. Open the xstable table, look at the data, and find that multiple pieces of data have been successfully inserted, and the XSID value automatically increases by 1 at a time. After setting the growth, sql can also ignore the xsid field and write it directly in the form of figure 3.

7. Open the design interface of table xstable, and the value set by Auto Increment in the chart is the initial value of automatic growth.

Thank you for reading! About the mysql setting data table primary key and self-growth method to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: Data growth fields success data tables methods statements values types diagrams content more interface facets such as diagrams queries design selection good practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei MySQL Shulou Technology Shulou Tech Info