mysql给表添加外键并查询

CREATE TABLE `heart` (
 `heart_ID` int(255) NOT NULL AUTO_INCREMENT,
 `heart_name` varchar(255) CHARACTER SET utf8 NOT NULL,
 `heat_anthor` varchar(255) CHARACTER SET utf8 NOT NULL,
 `heart_path` varchar(255) CHARACTER SET utf8 NOT NULL,
 `heat_time` date NOT NULL,
 `guanlianIndex` int(255) NOT NULL,
  PRIMARY KEY (`heart_ID`),
  FOREIGN KEY (guanlianIndex) REFERENCES music(music_ID)#建立外键与music表中的主键music_ID建立约束
)
// 名字,作者,风格(验证查询音乐表中的字段)
SELECT  music.music_name,music.music_author,music.music_style
    FROM music,heart
    WHERE heart.guanlianIndex=music.music_ID;

 

posted @ 2016-08-03 14:54  咚咚锵咚呛  阅读(2285)  评论(0编辑  收藏  举报