大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说mysql ddl dml dql_人际关系总结,希望您对编程的造诣更进一步.
以下是MySQL 5.7版本中各种DDL操作的执行方式,总结一下:
因为用第三方工具同样需要消耗IO以及CPU等资源。
CREATE INDEX name ON table (col_list);(ALTER TABLE tbl_name ADD INDEX name (col_list);) DROP INDEX name ON table;(ALTER TABLE tbl_name DROP INDEX name;) ALTER TABLE tbl_name RENAME INDEX old_index_name TO new_index_name, ALGORITHM=INPLACE, LOCK=NONE; CREATE FULLTEXT INDEX name ON table(column); CREATE TABLE geom (g GEOMETRY NOT NULL);ALTER TABLE geom ADD SPATIAL INDEX(g), ALGORITHM=INPLACE, LOCK=SHARED; ALTER TABLE tbl_name DROP INDEX i1, ADD INDEX i1(key_part,...) USING BTREE, ALGORITHM=INPLACE;
代码100分
代码100分ALTER TABLE tbl_name ADD PRIMARY KEY (column) ALTER TABLE tbl_name DROP PRIMARY KEY
ALTER TABLE tbl_name DROP PRIMARY KEY, ADD PRIMARY KEY (column)
列操作
ALTER TABLE tbl_name ADD COLUMN column_name column_definition, ALTER TABLE tbl_name DROP COLUMN column_name ALTER TABLE tbl CHANGE old_col_name new_col_name data_type ALTER TABLE tbl_name MODIFY COLUMN col_name column_definition FIRST ALTER TABLE tbl_name CHANGE c1 c1 BIGINT ALTER TABLE tbl_name CHANGE COLUMN c1 c1 VARCHAR(255) ALTER TABLE tbl_name ALTER COLUMN col SET DEFAULT literal ALTER TABLE tbl ALTER COLUMN col DROP DEFAULT ALTER TABLE table AUTO_INCREMENT=next_value ALTER TABLE tbl_name MODIFY COLUMN column_name data_type NULL ALTER TABLE tbl_name MODIFY COLUMN column_name data_type NOT NULL ALTER TABLE t1 MODIFY COLUMN c1 ENUM("a", "b", "c", "d")
代码100分ALTER TABLE t1 ADD COLUMN (c2 INT GENERATED ALWAYS AS (c1 + 1) STORED) ALTER TABLE t1 MODIFY COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) STORED FIRST ALTER TABLE t1 DROP COLUMN c2, ALGORITHM=INPLACE, LOCK=NONE; ALTER TABLE t1 ADD COLUMN (c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL) ALTER TABLE t1 MODIFY COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL FIRST ALTER TABLE t1 DROP COLUMN c2, ALGORITHM=INPLACE
ALTER TABLE tbl1 ADD CONSTRAINT fk_name FOREIGN KEY index (col1)REFERENCES tbl2(col2) referential_actions; ALTER TABLE tbl DROP FOREIGN KEY fk_name;
ALTER TABLE tbl_name ROW_FORMAT = row_format ALTER TABLE tbl_name KEY_BLOCK_SIZE = value ALTER TABLE tbl_name STATS_PERSISTENT=0, STATS_SAMPLE_PAGES=20, STATS_AUTO_RECALC=1, ALGORITHM=INPLACE, LOCK=NONE; ALTER TABLE tbl_name CHARACTER SET = charset_name, ALGORITHM=INPLACE, LOCK=NONE; ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name, ALGORITHM=COPY; OPTIMIZE TABLE tbl_name; ALTER TABLE tbl_name FORCE, ALGORITHM=INPLACE, LOCK=NONE; ALTER TABLE tbl_name ENGINE=InnoDB, ALGORITHM=INPLACE, LOCK=NONE; ALTER TABLE old_tbl_name RENAME TO new_tbl_name, ALGORITHM=INPLACE, LOCK=NONE;
ALTER TABLE tbl_name ENCRYPTION="Y", ALGORITHM=COPY;
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/11128.html