Home>Article>Database> What should you pay attention to when modifying tables in PHP? What are the common modification tables?

What should you pay attention to when modifying tables in PHP? What are the common modification tables?

慕斯
慕斯 Original
2021-06-28 15:34:48 1833browse

We have learned so much about PHP, but I wonder what you need to pay attention to when modifying tables in PHP? What are the common modification tables? Have you fully mastered it? If not, then follow this article to continue learning

Related recommendations:What are the options for data tables in PHP? What is a storage engine?

Modify the table

Some instructions:

1, modify the table, It refers to modifying the structure of the table - just as creating a table also sets the structure of the table.

2. Almost everything you can do by creating a table can be done by modifying the table - but it is not recommended to modify the table. Instead, you should basically determine the structure of the table when you create the table.

3. Generally speaking, yes,

3.1 can add, delete and modify fields;

3.2 can add, delete and modify indexes

4. Table options are usually "modified". Even if no table options are written, they have their default values.

Common ones:

  • Add fields: alter table table name add [column] new field name field type [field attribute List]

  • Modify fields: (and can rename): alter table table name change [column] old field name new field name new field type [new field attribute list];

  • Delete fields. alter table table name drop [column] field name;

  • #Add ordinary index: alter table table name addkey [index name](field name 1[, field name 2.. ]) Add unique index (constraint): alter table table name add unique key (field name 1 [, field name 2..]) Add primary key index (constraint): alter table table name add primary key (field name 1 [, field name Name 2..]):

  • Modify table name: alter table old table name

  • rename[to]new table name;

#The following demonstrates modifying the table:

alter table tab_xuanxiang add column email varchar(50); alter table tab_xuanxiang add key (age);/*添加一个普通索引*/

Related learning recommendations:mysql tutorial(video)

The above is the detailed content of What should you pay attention to when modifying tables in PHP? What are the common modification tables?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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