Home > Database > Mysql Tutorial > Summary of usage examples of mysql modifying database tables

Summary of usage examples of mysql modifying database tables

伊谢尔伦
Release: 2017-06-11 10:00:40
Original
1898 people have browsed it

When we need to modify the data table name or modify the data table fields, we need to use the MySQL ALTER command. Before starting this tutorial, let us first create a table named: testalter_tbl. root@host# mysql -u root -p password; Enter password:******* mysql> use TUTORIALS; Database changed mysql> create table testalter_tbl -> ( -> i INT, -> c CHAR(1)

1. Share an example of the MySQL ALTER command

Summary of usage examples of mysql modifying database tables

## Introduction: MySQLALTER command When we need to modify the data table name or modify the data table fields, we need to use the MySQLALTER command. Before starting this tutorial, let us first create a table named: testalter_tbl. root@host#...

2. MySQL Modify Data Table (MYSQL Data Table Operation Tutorial 2)

Summary of usage examples of mysql modifying database tables

#Introduction: Modify the table structure Use the ALTER TABLE statement to modify the table structure. Modifying the table structure means adding or deleting fields, modifying field names or field types, setting or canceling primary keys and foreign keys, setting or canceling indexes, and modifying table comments, etc. The syntax format is as follows: ALTER[IGNORE] TABLE data table name alter_spec[,alter_spec]...;

3. You want to modify the data table field information after laravel database migrate

Introduction: After executing php artisan migrate in laravel, data is also inserted into the database. But now I want to modify the target structure. For example, I want to add a default value of 0 to the title field to withdraw the data. How can I ensure that the database data is still there and the data table can be modified? ps (I tried if I add a...

4. notnull use sql command to modify the data A field in the table is non-null not null statement

Summary of usage examples of mysql modifying database tables

##Introduction: notnull:notnull using sql command Statement to modify a field in the data table to be non-null not null: ALTER TABLE table1 ALTER COLUMN [name] varchar(60) NULL; table1 table name name Why add [] to the field name? Because name is a SQL keyword, conflicts will occur. Error, just in case. If the name field has been indexed, if you need to modify it, you must first delete the index to proceed correctly.

Use sql command. Modify a field in the data table to be non-null (not null) statement_PHP tutorial

Introduction : Use the sql command to modify a field in the data table to be non-null (not null). ALTER TABLE table1 ALTER COLUMN [name] varchar(60) NULL; table1 table name why add [] to the field name, because name is sql keywords will conflict and errors will occur, just in caseSummary of usage examples of mysql modifying database tables

6.

Mysql string type field sorting issues

Introduction: MySQL string type field sorting problem I have a field A, varchar type. There are 3 pieces of data in it. After sorting by A DESC, the order is as follows: 2013.03, 2013.02, 2013.04 How can I make the latest time appear first? Without modifying the data table field type.

7.

Use sql command to modify the statement that a field in the data table is not null

Introduction: Use sql command to modify the statement that a field in the data table is not null. ALTER TABLE table1 ALTER COLUMN [name] varchar(60) NULL; table1 table name name field name Why add [], because name is a sql keyword that will cause conflicts and errors, just in case. if

8. Mysql string type field sorting related issues

Introduction: mysql string type field sorting issue I have a field A , varchar type. There are 3 pieces of data in it. After sorting by A DESC, the order is as follows: 2013.03, 2013.02, 2013.04. How can I make the one with the latest time come first? Without modifying the data table field type.

9. Temporary memory table is very fast, but does not support text solution

Introduction: Temporary memory The table is very fast, but it does not support text. I want to copy the original table data structure directly to the temporary table for query operation. As a result, one of the tables is text, and there is no way to reduce the data content, and varchar cannot be accommodated. Either modify the data table and re-take out the serialized array in the text, or jointly query the text in the memory table. Or... what? Create a temporary memory table with the original data, then take out the text content separately and create another one. Joint query of two tables in a temporary memory table

10. sql alert Modify the table or add columns

Introduction: The alert command of sql is used to modify the data table name, add columns, delete columns, modify field data types, etc. Well, let's look at the examples one by one. Database ALTER TABLE syntax To add a column to a table, use the following syntax: ALTER TABLE table_name ADD column_name datatype Let’s look at an example of adding an example: ALTER TABLE tname ALTER COLUMN data

【Related Q&A recommendations】:

How do the ios client and php server handle emoji expressions?

python - flask_sqlalchemy loop query results are the same

php - want to modify the data table field information after laravel database migrate

In mysql table, is it possible to insert data into multiple connections at the same time?

The above is the detailed content of Summary of usage examples of mysql modifying database tables. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template