Mysql uses the command line to set the primary key: first enter the mysql command line tool and enter the target database through the use keyword; then add the primary key through the command ADD PRIMARY KEY and press Enter.
Mysql uses the command line to set the primary key:
1. First, we enter the mysql command line through the terminal Tool
#2, and then use the use keyword to enter the target database.
3. If the original table already has a primary key, we must first delete the original primary key through the DROP PRIMARY KEY command:
ALTER TABLE `jingyan` DROP PRIMARY KEY;
4. To be more intuitive, we can see on the visual database tool that the primary key of the table is no longer there.
5. To add a primary key, you can add it through the command: ADD PRIMARY KEY
ALTER TABLE `jingyan` ADD PRIMARY KEY ( `id` )
6. Enter the command After pressing the Enter key, you can see the characters indicating that query ok was executed successfully.
#7. Return to the database visualization tool. You can see that the current table has a primary key added to the id column.
More related free learning recommendations: mysql tutorial(Video )
The above is the detailed content of How to set primary key in mysql using command line. For more information, please follow other related articles on the PHP Chinese website!