Home  >  Article  >  Database  >  How to set primary key in mysql using command line

How to set primary key in mysql using command line

coldplay.xixi
coldplay.xixiOriginal
2020-11-12 09:26:546464browse

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.

How to set primary key in mysql using command line

Mysql uses the command line to set the primary key:

1. First, we enter the mysql command line through the terminal Tool

How to set primary key in mysql using command line

#2, and then use the use keyword to enter the target database.

How to set primary key in mysql using command line

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;

How to set primary key in mysql using command line

4. To be more intuitive, we can see on the visual database tool that the primary key of the table is no longer there.

How to set primary key in mysql using command line

5. To add a primary key, you can add it through the command: ADD PRIMARY KEY

ALTER TABLE `jingyan` ADD PRIMARY KEY ( `id` )

How to set primary key in mysql using command line

6. Enter the command After pressing the Enter key, you can see the characters indicating that query ok was executed successfully.

How to set primary key in mysql using command line

#7. Return to the database visualization tool. You can see that the current table has a primary key added to the id column.

How to set primary key in mysql using command line

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn