Mysql sets the primary key and auto-increment method of the data table: first start MySQL, open navicat to create a new table; then add fields and types; then execute relevant statements to insert data; finally select the field, and click below Put a check mark in front of Auto Increment to auto-increase.
##More related free learning recommendations: mysql tutorial(Video)
Mysql sets the primary key and auto-increment method of the data table:
1. Start MySQL, open navicat, and create a new database aaa, right-click Tables, select new table, and create a new table. #2. Add field xsid, type is int, add field xsname, type is vachar. As shown in the figure, select the field xsid, and set this field as the primary key by clicking Primary Key, or at position 2 in the figure. Save the table as xstable. #3. Open the table xstable, create a new query, and enter the sql statement in the picture. After successful execution, a piece of data will be inserted into the table. #4. Set the xsid value in sql to empty. The first execution of the statement can be successful. The xsid is stored as 0 by default. When executing the second time, an error is reported. As shown in the picture. It can be seen that if the specific value of xsid cannot be set, the execution cannot be successful. 5. Open the design interface of the table xstable, select the xsid field, and put a check in front of Auto Increment below to select automatic growth. #6. On the query page, execute the sql statement with an empty xsid again. The execution will be successful and can be executed multiple times. Open the xstable table, check the data, and find that multiple pieces of data have been successfully inserted, and the xsid value automatically increases by 1 each time. After setting the auto-increment, SQL can also ignore the xsid field and directly write it in the form of Figure 3. #7. Open the design interface of table xstable. The value set by Auto Increment in the figure is the initial value of automatic growth.The above is the detailed content of How to set the primary key and auto-increment of data table in mysql. For more information, please follow other related articles on the PHP Chinese website!