MYSQL主键,索引,外键

发布时间:2024年01月16日

主键索引:

ALTER TABLE DES_ADSL ADD CONSTRAINT PK_DES_ADSL PRIMARY KEY (SERVICEID, SERVICEIDSEQ);

ALTER TABLE DES_ADSL ADD DROP?PRIMARY KEY;

CREATE INDEX IDX_ADDR_SEGM_FROM ON ADDR_SEGM (ADDR_FROM ASC);
CREATE INDEX IDX_ADDR_SEGM_ID
? ON ADDR_SEGM (SEGM_ID ASC);
CREATE INDEX IDX_ADDR_SEGM_ID_2
? ON ADDR_SEGM (PARENT_SEGM_ID ASC);
CREATE INDEX IDX_ADDR_SEGM_REGIONID
? ON ADDR_SEGM (REGION_ID ASC);
CREATE INDEX IDX_ADDR_SEGM_RELA_ID
? ON ADDR_SEGM (RELA_ID ASC);
CREATE INDEX IDX_ADDR_SEGM_SEGM_NAME
? ON ADDR_SEGM (SEGM_NAME ASC);
CREATE INDEX IDX_ADDR_SEGM_STANDNAME
? ON ADDR_SEGM (STAND_NAME ASC);

外键:

SELECT
    CONSTRAINT_NAME,
    TABLE_NAME,
    COLUMN_NAME,
    REFERENCED_TABLE_NAME,
    REFERENCED_COLUMN_NAME
FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
    REFERENCED_TABLE_SCHEMA = 'resdb';
+--------------------------------+--------------------------+----------------+-----------------------+------------------------+
| CONSTRAINT_NAME                | TABLE_NAME               | COLUMN_NAME    | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+--------------------------------+--------------------------+----------------+-----------------------+------------------------+
| FK_ODNID                       | AN_ODN_PICTURE           | ODNID          | AN_ODN                | ID                     |
| FK_DES_SERVICEORDER_SERVICE1   | DES_SERVICEORDER_SERVICE | SERVICEORDERID | DES_SERVICEORDER      | SERVICEORDERID         |
| FK_G_ROOM_F_REFERENCE_G_EQUIP_ | G_ROOM_FIXING            | EQUIP_TYPE     | G_EQUIP_TYPE          | ID                     |
| FK_TP_FACTO_REFERENCE_FACTORY  | TP_FACTORY_CARD_TYPE     | FACTORY_ID     | FACTORY               | ID                     |
+--------------------------------+--------------------------+----------------+-----------------------+------------------------+
4 rows in set (0.00 sec)
删除外键:
alter table AN_ODN_PICTURE drop foreign key FK_ODNID; 
alter table DES_SERVICEORDER_SERVICE drop foreign key FK_DES_SERVICEORDER_SERVICE1; 
alter table G_ROOM_FIXING drop foreign key FK_G_ROOM_F_REFERENCE_G_EQUIP_; 
alter table TP_FACTORY_CARD_TYPE drop foreign key FK_TP_FACTO_REFERENCE_FACTORY; 


文章来源:https://blog.csdn.net/jycjyc/article/details/135622914
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。