- Modify field
ALTER TABLE `XXXXXXXX`
CHANGE `mtime` `mtime` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL COMMENT '更新时间',
CHANGE `ctime` `ctime` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建日期',
CHANGE `deleted` `deleted` tinyint(4) DEFAULT '0' COMMENT '0:未删除 1.删除';
2. Add fields
ALTER TABLE `XXXXXXXX`
ADD `mtime` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL COMMENT '更新时间',
ADD `ctime` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建日期',
ADD `deleted` tinyint(4) DEFAULT '0' COMMENT '0:未删除 1.删除';
3. Add index
ALTER TABLE `XXXXXXXXX`
ADD KEY `idx_app_id` (`app_id`),
ADD KEY `idx_app_id_consumer` (`app_id`,`consumer`),
ADD KEY `idx_app_id_member` (`app_id`,`member`);
View index show index from database table name
alter table database add index index name (database field name)
PRIMARY KEY (primary key index)
ALTER TABLE table_name
ADD PRIMARY KEY ( column
)
UNIQUE (unique index)
ALTER TABLE table_name
ADD UNIQUE ( column
)
INDEX (ordinary index)
mysql >ALTER TABLE table_name
ADD INDEX index_name ( column
)
FULLTEXT (full text index)
ALTER TABLE table_name
ADD FULLTEXT (`col
Multi-column index of
the ALTER TABLE table_name
the ADD INDEX index_name ( column1
, column2
, column3
)
1. general index.
This is the most basic index, it has no restrictions. It has the following creation methods:
(1) Create index: CREATE INDEX indexName ON tableName(tableColumns(length)); If it is CHAR, VARCHAR type, length can be less than the actual length of the field; if it is BLOB and TEXT type, length must be specified , The same below.
(2) Modify the table structure: ALTER tableName ADD INDEX [indexName] ON (tableColumns(length))
(3) Specify directly when creating the table: CREATE TABLE tableName ([…], INDEX [indexName] (tableColumns(length));
2. Unique index.
It is similar to the previous "ordinary index", except that the value of the index column must be unique, but null values are allowed. If it is a composite index, the combination of column values must be unique. It has the following creation methods:
(1) Create index: CREATE UNIQUE INDEX indexName ON tableName(tableColumns(length))
(2) Modify table structure: ALTER tableName ADD UNIQUE [indexName] ON (tableColumns(length))
(3) Specify directly when creating a table: CREATE TABLE tableName ([…], UNIQUE [indexName] (tableColumns(lengt
View index
show index from tb_wz_all;