音乐网站的数据库表设计,使用mysql创建表语句
时间: 2024-05-24 14:12:30 浏览: 111
基于ssm+mysql在线音乐网站设计与实现.docx
以下是一个简单的音乐网站的数据库表设计,并附有MySQL创建表语句:
1. 用户表(user)
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2. 歌手表(singer)
CREATE TABLE `singer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`gender` int(1) NOT NULL COMMENT '0女 1男',
`image` varchar(100) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3. 歌曲表(song)
CREATE TABLE `song` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`singer_id` int(11) NOT NULL,
`album` varchar(100) DEFAULT NULL,
`image` varchar(100) DEFAULT NULL,
`duration` int(11) DEFAULT NULL COMMENT '时长(秒)',
`lyric` text,
PRIMARY KEY (`id`),
KEY `singer_id` (`singer_id`),
CONSTRAINT `song_ibfk_1` FOREIGN KEY (`singer_id`) REFERENCES `singer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4. 歌单表(playlist)
CREATE TABLE `playlist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`user_id` int(11) NOT NULL,
`description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `playlist_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5. 歌曲与歌单的关联表(playlist_song)
CREATE TABLE `playlist_song` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`playlist_id` int(11) NOT NULL,
`song_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `playlist_id` (`playlist_id`),
KEY `song_id` (`song_id`),
CONSTRAINT `playlist_song_ibfk_1` FOREIGN KEY (`playlist_id`) REFERENCES `playlist` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `playlist_song_ibfk_2` FOREIGN KEY (`song_id`) REFERENCES `song` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
以上是一个简单的音乐网站的数据库表设计,可以根据实际需求进行修改和优化。
阅读全文