MySQL knowledge points for the second-level computer exam mysql alter command

MySQL knowledge points for the second-level computer exam mysql alter command

Usage of alter command in mysql to edit table structure. The specific contents are as follows

Modify field type

mysql> alter table employee change depno depno int(5) not null;

Add index

mysql> alter table table name add index index name (field name 1 [, field name 2 ...]);

example:

mysql> alter table employee add index emp_name (name);

Add the primary keyword index

mysql> alter table table name add primary key (field name);

example:

mysql> alter table employee add primary key(id);

Add unique restriction index

mysql> alter table table name add unique index name (field name);

example:

mysql> alter table employee add unique emp_name2(cardnumber);

View the index of a table

mysql> show index from table name;

example:

mysql> show index from employee;

Delete an index

mysql> alter table table name drop index index name;

example:

mysql>alter table employee drop index emp_name;

Modify table: add fields:

mysql> ALTER TABLE table_name ADD field_name field_type;

View the table:

mysql> SELECT * FROM table_name;

Modify the original field name and type:

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

To delete a field:

ALTER TABLE table_name DROP field_name

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

Finally, I wish you all success in passing the computer level test.

You may also be interested in:
  • Detailed explanation of MySQL event modification events (ALTER EVENT), disabling events (DISABLE), enabling events (ENABLE), event renaming and database event migration operations
  • Summary of MySQL ALTER command knowledge points
  • Detailed introduction to mysql alter table modification command
  • mysql alter table modification table command summary
  • mysql alter table command to modify table structure example
  • Detailed explanation of the mysql alter table command to modify the table structure
  • MySQL ALTER command usage details
  • MySQL database ALTER command explanation
  • Basic usage and speed optimization of alter table command in MySQL
  • MySQL Learning Notes 5: Modify Table (alter table)
  • Detailed explanation of MySQL alter ignore syntax

<<:  Detailed explanation of three ways to cut catalina.out logs in tomcat

>>:  Detailed explanation of using javascript to handle common events

Recommend

MySQL Series 10 MySQL Transaction Isolation to Implement Concurrency Control

Table of contents 1. Concurrent access control 2....

A practical record of restoring a MySQL Slave library

Description of the situation: Today, I logged int...

Detailed steps to install mysql in Win

This article shares the detailed steps of install...

Vue uses echarts to draw an organizational chart

Yesterday, I wrote a blog about the circular prog...

Interviewer asked how to achieve a fixed aspect ratio in CSS

You may not have had any relevant needs for this ...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

Dissecting the advantages of class over id when annotating HTML elements

There are very complex HTML structures in web pag...

Nginx location matching rule example

1. Grammar location [=|~|~*|^~|@] /uri/ { ... } 2...

Docker Detailed Illustrations

1. Introduction to Docker 1.1 Virtualization 1.1....

How to install Nginx in CentOS7 and configure automatic startup

1. Download the installation package from the off...

docker cp copy files and enter the container

Enter the running container # Enter the container...

jQuery canvas draws picture verification code example

This article example shares the specific code of ...

Modularity in Node.js, npm package manager explained

Table of contents The basic concept of modularity...

How to use Nginx to solve front-end cross-domain problems

Preface When developing static pages, such as Vue...