How to express the statement that mysql adds a column
This article mainly explains the "mysql add column sentence how to express", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "mysql add column sentence how to express" it!
The statement that mysql adds columns is "ALTER TABLE" and the syntax is "ALTER TABLE table name ADD new column name data type [constraint] [FIRST];". The FIRST keyword is optional, adding columns at the end of the table if omitted, or at the beginning of the table if not omitted.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
A MySQL data table is made up of rows and columns. The "column" of the table is usually called a Field, and the "row" of a table is called a Record. As the business changes, you may need to add new fields (columns) to existing tables.
In mysql, the statement to add columns is "ALTER TABLE"; this statement can change the structure of the original table, such as adding or deleting columns, changing the original column type, renaming columns or tables, and so on.
Add the syntax format of the column:
ALTER TABLE table name ADD new column name data type [constraint] [FIRST]
The syntax format is described as follows:
The name of the table is the name of the data table
The new column name is the name of the column (field) to be added
The data type is the data type in which the field to be added can store data.
[constraints] are optional and are used to constrain added fields.
[FIRST] is optional to add columns at the beginning of the table; if omitted, columns are added at the end of the table by default
Example: we have a student data table whose table structure looks like this
Use the ALTER TABLE statement to add a field of type INT age at the end
ALTER TABLE student ADD age INT (4)
View a table structure
You can see that the age field has been added to the student table, and the field is in the last location of the table. The field was added successfully.
Now, try using the FIRST keyword to add a field of type INT stuId to the first column of the table
ALTER TABLE student ADD stuId INT (4) FIRST
View a table structure
As you can see, the stuId field has been added to the student table, and the field is in the first position in the table. The field was added successfully.
Thank you for your reading, the above is the content of "mysql add column sentence how to express", after the study of this article, I believe you have a deeper understanding of how to express the sentence of mysql column, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!