MySql中如何删除外键?

MySql中如何删除外键?,第1张

1lesson表:�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2<!--StartFragment --�0�2我现在想删除sid这个列的外键:别的同学的机子都可以删除,但是我的机子就不行,我们的MySql是一个版本的,不知道是什么原因?谁帮我解答下?????问题补充:<div class="quote_title"hanyuanbo 写道</div<div class="quote_div"你的同学可以删除,而且版本也一样,可能是你们表的结构不同。你可以先将那个包含外键的那个表备份下,删除掉那个表格,这样就可以删除外键了。之后再把备份恢复下就好了。<img src="/images/smiles/icon_smilegif"/ </div /<div class="quote_title"hanyuanbo 写道</div<div class="quote_div"你的同学可以删除,而且版本也一样,可能是你们表的结构不同。你可以先将那个包含外键的那个表备份下,删除掉那个表格,这样就可以删除外键了。之后再把备份恢复下就好了。<img src="/images/smiles/icon_smilegif"/ </div /就是因为有外键,所以导致列和表都删除不了,除非把整个Database都删除,那样的话我做的整个database都没了,只要找到能删除外键的,就可以把这个列删除,也就照样可以把这个表删除!!!!郁闷啊就是不能删除哪个外键!!问题补充:<div class="quote_title"hanyuanbo 写道</div<div class="quote_div"在删除那个把该外键作为主键的表之前,你先把包含外键的那个表中的外键全部删掉,置为null,或者直接将那列删掉,这样就没有地方引用这些外键,你就可以将那个表删除掉了。希望可以帮忙。记得以前做过类似的东西,删除将外键作为主键的表之前,必须将引用到这个键的内容置空,即没有引用该键,这样便可以删除了。</div /alter table lesson drop index key; /&nbsp; 可是这个语句删除不了外键啊,我也知道只要把外键删掉就可以删除表了,关键是我不知道怎么删外键了!!!!

MySQL主键的限制,每一个分区表中的公式中的列,必须在主键/unique key 中包括
MYSQL的官方文档里是这么说明的
1851 Partitioning Keys, Primary Keys, and Unique Keys
This section discusses the relationship of partitioning keys with primary keys and unique keys The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have
In other words,every unique key on the table must use every columnin the table's partitioning expression (This also includes the table's primary key, since it is by definition a unique key This particular case is discussed later in this section) For example, each of the following table creation statements is invalid:
解决办法是创建复合主键,将id和你的分区字段创建复合主键


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

原文地址: http://outofmemory.cn/yw/13370570.html

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

发表评论

登录后才能评论

评论列表(0条)

保存