zoukankan      html  css  js  c++  java
  • Mysql常用命令行大全(四)外键及其它

    表构成

    mysql> show tables;

    +----------------------+
    | Tables_in_WebComplie |
    +----------------------+
    | Compile |

    | Content |
    | User      |
    +----------------------+

    Compile表结构

    mysql> show create table Compile;

    | Compile | CREATE TABLE `Compile` (
    `compileID` int(11) NOT NULL AUTO_INCREMENT,
    `userName` varchar(128) NOT NULL,
    `boardName` varchar(128) NOT NULL,
    `panelName` varchar(128) NOT NULL,
    `contentID` int(11) NOT NULL,
    `complieDate` datetime NOT NULL,
    `binPath` varchar(128) NOT NULL,
    `compileState` tinyint(1) NOT NULL,
    PRIMARY KEY (`compileID`),
    UNIQUE KEY `UQ_Compile_CompileID` (`compileID`),
    KEY `ContentID` (`contentID`),
    KEY `Compile_Panel_PanelName` (`panelName`),
    KEY `Compile_User_UserName` (`userName`),
    CONSTRAINT `Compile_User_UserName` FOREIGN KEY (`userName`) REFERENCES `User` (`userName`),
    CONSTRAINT `Compile_ibfk_2` FOREIGN KEY (`contentID`) REFERENCES `Content` (`contentID`),
    CONSTRAINT `Compile_Panel_PanelName` FOREIGN KEY (`panelName`) REFERENCES `Panel` (`PanelName`)
    ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin1 |

    删除外键“UserID”:

    mysql> alter table Compile drop foreign key Compile_User_UserName;  //注意删除的是外键约束“Compile_User_UserName”,即外键UserID

    增加外键:

    mysql> alter table Compile add constraint Compile_User_UserName foreign key(userName) references User(userName);

  • 相关阅读:
    [JSOI2008]最小生成树计数
    [SCOI2009]windy数
    Sql Server 存储过程
    Sql Server 表操作
    .NET WebService中使用 Session
    从头入手jenkins
    swiftlint 你所要知道的所有!!
    swiftlint swift代码规范检查神器
    使用RxSwift 实现登录页面的条件绑定
    iOS 设置不同环境下的配置 Debug Release 生产 测试 等等
  • 原文地址:https://www.cnblogs.com/jiangzhaowei/p/6595201.html
Copyright © 2011-2022 走看看