mysql如何取消主码约束

mysql如何取消主码约束,第1张

主码完整性约束的设置有两种方法:1.在定义数据项的时候就声明它为主码2.在表创建完成之后增加完整性约束对应于1,撤销完整性约束alter table employeedrop primary key对应于2.alter table emloyeedrop constraint PK_enoPK_eno 为当初创建完整性约束时为该约束性定义的名字

对于非unique索引和外键可以可以设置禁用,其他的,暂时还没发现。

想要禁用非unique索引的话可以用:ALTER TABLE ... DISABLE KEYS,这个语句需要是MyISAM的表才行。

想要禁用外键的话可以用类似下面的语句:

mysql>SET foreign_key_checks = 0

mysql>SOURCE dump_file_name

mysql>SET foreign_key_checks = 1

详细的说明,可以参考mysql文档,这里贴两段摘自MySql 5.6版的英文说明,帮助理解。

If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.While the nonunique indexes are disabled, they are ignored for statements such as

SELECT and EXPLAIN that otherwise would use them.

To make it easier to reload dump files for tables that have foreign key relationships,

mysqldump automatically includes a statement in the dump output to set

foreign_key_checks to 0. This avoids problems with tables having to be reloaded in a particular order when the dump is reloaded. It is also possible to set this variable manually:mysql>SET foreign_key_checks = 0

mysql>SOURCE dump_file_name

mysql>SET foreign_key_checks = 1

This enables you to import the tables in any order if the dump file contains tables that are not correctly ordered for foreign keys. It also speeds up the import operation. Setting

foreign_key_checks to 0 can also be useful for ignoring foreign key constraints during LOAD DATA and ALTER TABLE operations. However, even ifforeign_key_checks = 0

, InnoDB does not permit the creation of a foreign key constraint where a column references a nonmatching column type. Also, if an InnoDB table has foreign key constraints,

ALTER TABLE cannot be used to change the table to use another storage engine. To alter the storage engine, drop any foreign key constraints first.


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/8607427.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-18
下一篇2023-04-18

发表评论

登录后才能评论

评论列表(0条)

    保存