You can set the primary key and auto-increment for the table through sql, or you can use the tool navicat to set the primary key and auto-increment graphically.
##Open the navicat tool, connect to the mysql server, after selecting the database, select a table, right-click and select [Design Table] 】 (For demonstration and testing here, just select a table) (Recommended tutorial: navicat tutorial)
On the design table page, you can see all the field information of the current table. The student table we selected has an id field. Currently, the table does not have a primary key field
## As shown in the picture,
right-click on the last column and select the primary key to set the field as the primary key. You can also click the left mouse button directly to quickly add and cancel the primary keyAfter setting the primary key, you can see the logo of a lock with the word 1. Because a table can add primary keys to multiple fields, it is a joint primary key, so it displays as primary key 1. , primary key 2, etc.
After the primary key setting is completed, it has not been incremented yet. After selecting the id field
, check the box below as shown in the figure. Select auto-increment, so that the ID will automatically increment by a value after each record is inserted
After setting the primary key and auto-increment, click Save and close the current window.The above is the detailed content of How to use navicat to add primary keys and auto-increment to database tables. For more information, please follow other related articles on the PHP Chinese website!