The method of operating data tables in MySQL is not complicated. The following will introduce you in detail to the implementation methods of adding fields, modifying fields, deleting fields, and obtaining table names in MYSQL. I hope it will be helpful for you to learn to add fields in MySQL. .
The method of adding fields in MySQL is not complicated. The following will introduce you in detail to the implementation methods of adding fields and modifying fields in MYSQL. I hope it will help you learn about adding fields in MySQL. will help.
1Add table fields
alter table table1 add transactor varchar(10) not Null; alter table table1 add id int unsigned not Null auto_increment primary key
Examples of statements added after specific fields:
ALTER TABLE <表名> ADD <新字段名><数据类型>[约束条件]; ALTER TABLE MyTableName ADD newDBField varchar(30) NULL AFTER existDBField; ALTER TABLE tableName001 ADD WebAdminPass varchar(30) NULL AFTER Result;
2. Modify the field type of a table and specify it as empty or non-empty
alter table 表名称 change 字段名称 字段名称 字段类型 [是否允许非空]; alter table 表名称 modify 字段名称 字段类型 [是否允许非空]; alter table 表名称 modify 字段名称 字段类型 [是否允许非空];
3. Modify the field name of a table and specify it as empty or non-empty
alter table 表名称 change 字段原名称 字段新名称 字段类型 [是否允许非空
4 If you want to delete a field, you can use the command:
ALTER TABLE mytable DROP 字段名;
mysql SQL to obtain Query statement for table name & field name
1: Query all table names in the database
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table'; table_schema:数据库名称 information_schema 表示系统库。 table_type='base table‘:限定只查询基表。
2: Query all field names column_name
select column_name from information_schema.columns where table_schema='csdb' and table_name='users'; table_schema:数据库名 table_name:表名
select count(*) from information_schema.columns where table_schema='yanfa' and table_name='tableName001' and column_name='Result1'; #select table_name from information_schema.tables where table_schema='yanfa' and table_type='base table';
mysql tutorial(Video)
The above is the detailed content of How MySQL operates data tables. For more information, please follow other related articles on the PHP Chinese website!