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

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

How to use Maxwell to synchronize MySQL data in real time

Table of contents About Maxwell Configuration and...

Vue keeps the user logged in (various token storage methods)

Table of contents How to set cookies Disadvantage...

Vue achieves seamless carousel effect

This article shares the specific code of Vue to a...

HTML tutorial, easy to learn HTML language

1. <body background=image file name bgcolor=co...

Practical example of Vue virtual list

Table of contents Preface design accomplish summa...

How to install Jenkins on CentOS 8

To install Jenkins on CentOS 8, you need to use t...

Docker builds jenkins+maven code building and deployment platform

Table of contents Docker Basic Concepts Docker in...

Building an image server with FastDFS under Linux

Table of contents Server Planning 1. Install syst...

How to use docker to deploy dubbo project

1. First, use springboot to build a simple dubbo ...

How to Completely Clean Your Docker Data

Table of contents Prune regularly Mirror Eviction...