如何修改表中外键的名称,如外键名称为article\u ibfk\u 1,要改为'one'。
+--------------------+-------------------+-----------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | POSITION_IN_UNIQUE_CONSTRAINT | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+--------------------+-------------------+-----------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| def | test | PRIMARY | def | test | article | id | 1 | NULL | NULL | NULL | NULL |
| def | test | article_ibfk_1 | def | test | article | tag | 1 | 1 | test | tag | id |
+--------------------+-------------------+-----------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
2 rows in set (0.00 sec)
2条答案
按热度按时间2uluyalo1#
将其删除,然后使用新名称再次创建:
omhiaaxx2#
sp\u rename'article\u ibfk\u 1','one'
或
exec sp_rename@objname=n'article_ibfk_1',@newname=n'one';