Home Database Mysql Tutorial MySQL ALTER语法的运用方法_MySQL

MySQL ALTER语法的运用方法_MySQL

Jun 01, 2016 pm 01:20 PM
Practical application article

bitsCN.com 以下的文章主要介绍的是MySQL ALTER语法的实际运用,我们大家都知道MySQL ALTER语法在实际应用中的比例还是很大的,所以了解一下MySQL ALTER语法的实际运用可以很好的选择。
MySQL ALTER语法中ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]

alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
or ADD INDEX [index_name] (index_col_name,...)
or ADD PRIMARY KEY (index_col_name,...)
or ADD UNIQUE [index_name] (index_col_name,...)
or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
or CHANGE [COLUMN] old_col_name create_definition
or MODIFY [COLUMN] create_definition
or DROP [COLUMN] col_name
or DROP PRIMARY KEY
or DROP INDEX index_name
or RENAME [AS] new_tbl_name
or table_options
eg:
mysql> alter table topics change hotico hot_count int(4);
mysql> alter table topics alter hot_count set default 1;

补充:
加索引
mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]);

例子: mysql> alter table employee add index emp_name (name);
加主关键字的索引
mysql> alter table 表名 add primary key (字段名);
例子: mysql> alter table employee add primary key(id);
加唯一限制条件的索引
mysql> alter table 表名 add unique 索引名 (字段名);
例子: mysql> alter table employee add unique emp_name2(cardnumber);
MySQL ALTER语法运用:查看某个表的索引
mysql> show index from 表名;

例子: mysql> show index from employee;

删除某个索引
mysql> alter table 表名 drop index 索引名;

例子: mysql>alter table employee drop index emp_name;

修改表:增加字段:mysql> ALTER TABLE table_name ADD field_name field_type;
查看表:mysql> SELECT * FROM table_name;

修改原字段名称及类型:mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

删除字段:MySQL ALTER TABLE table_name DROP field_name;bitsCN.com

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

Sharing of practical application experience of WebSocket protocol in online voting applications Sharing of practical application experience of WebSocket protocol in online voting applications Oct 15, 2023 pm 12:28 PM

Practical application experience sharing of WebSocket protocol in online voting applications Introduction: With the popularity of the Internet and the continuous advancement of technology, more and more applications have chosen the WebSocket protocol when realizing real-time communication and interactive functions. This article will take the online voting application as an example, introduce the practical application experience of WebSocket protocol in this application, and provide specific code examples. 1. Background Introduction Online voting application is a typical application that requires real-time communication function. The traditional HTTP protocol is implemented in

In-depth understanding of the working principles and practical application of the Struts framework In-depth understanding of the working principles and practical application of the Struts framework Jan 04, 2024 am 10:26 AM

To understand the internal mechanism and practical application of the struts framework, specific code examples are required. Introduction: Struts is a web application development framework based on the MVC architecture. It provides a rich set of class libraries and APIs to help developers effectively organize and manage web applications. program. Understanding the internal mechanisms and practical applications of the Struts framework will help us better use this framework to develop powerful, stable and reliable Web applications. This article will introduce the internal mechanism of Struts in detail and give some practical applications.

How to add article in HTML5? How to add article in HTML5? Sep 12, 2023 am 11:37 AM

In this article, we will learn how to add articles in HTML5. One of the new segmentation elements in HTML5 is the tag. Articles are represented in HTML using tags. More specifically, the content contained within the element is different from the rest of the site's content (even though they may be related). Let us consider the following example to understand how to add an article in HTML5 Example 1 In the following example, we are using inline styles in the article element. <!DOCTYPEhtml><html><body><articlestyle="width:300px;border:2pxsolidgray;padding:

Recursive calling of Go language functions and practical application scenarios Recursive calling of Go language functions and practical application scenarios Mar 22, 2024 pm 09:42 PM

Title: Recursive Calling of Go Language Functions and Practical Application Scenarios In the Go language, recursive calling of functions is a powerful programming technique that can solve certain complex problems concisely. Recursive calling refers to a function calling itself directly or indirectly. By splitting a large problem into multiple similar small problems, recursive calling can help us better understand, design and implement algorithms. 1. What is recursive call? When a function calls itself during execution, this method of calling is called recursive call. Recursive functions need to satisfy two requirements when implementing them:

Interpretation of Vitalik's new article: Why does Rollup, whose blob space is not used efficiently, fall into development difficulties? Interpretation of Vitalik's new article: Why does Rollup, whose blob space is not used efficiently, fall into development difficulties? Apr 01, 2024 pm 08:16 PM

How to understand @VitalikButerin’s new article’s thoughts on Ethereum’s expansion? Some people say that Vitalik’s order for Blob Inscription is outrageous. So how do blob packets work? Why is the blob space not being used efficiently after the upgrade in Cancun? DAS data availability sampling in preparation for sharding? In my opinion, the performance of Cancun is usable after the upgrade, and Vitalik is worried about the development of Rollup. Why? Next, let me talk about my understanding: As I have explained many times before, Blob is a temporary data package that is decoupled from EVM calldata and can be directly called by the consensus layer. The direct benefit is that EVM does not need to access the Blob when executing transactions. data, thus resulting in lower execution layer computations

Use PyCharm's batch indentation function to improve code standardization Use PyCharm's batch indentation function to improve code standardization Dec 30, 2023 am 11:38 AM

Code Standardization Tool: Practical Application of PyCharm's Batch Indentation Function Introduction: In the field of software development, code standardization is a very important part. Good code specifications can not only improve the readability and maintainability of the code, but also reduce potential bugs. However, in the process of writing code, indentation inconsistency often occurs, which not only affects the appearance of the code, but may also lead to syntax errors. This article will introduce the batch indentation function in PyCharm, an excellent Python development tool, and its application in actual development.

Analysis of common web standards and their actual cases Analysis of common web standards and their actual cases Jan 13, 2024 pm 03:50 PM

Understand common Web standards and their practical application cases In today's digital era, the World Wide Web has become an important platform for people to obtain information, communicate, and conduct business activities. Web standards are the basis for ensuring that web pages display normally and operate stably on different browsers. This article will introduce some common web standards and illustrate their importance through practical application cases. First of all, HTML (Hypertext Markup Language) is the most basic part of the Web standards and is used to describe the structure and content of web pages. HTML uses tags to define whether

See all articles