Javaweb-資料庫設計案例

wangyin0425發表於2024-09-08





1. create table music( id int PRIMARY key, title varchar(32), alias varchar(32), image varchar(64), style varchar(8), type varchar(4), medium varchar(4), publish_time date, publisher varchar(16), number tinyint, barcode bigint, summary varchar(1024), artist varchar(16) );
2. create table song( id int unique, name varchar(32), serial_number tinyint, music_id int );
3. alter table song add CONSTRAINT fk_song_music FOREIGN key (music_id) REFERENCES music(id);
4. create table review( content varchar(256), rating tinyint, review_time datetime, music_id int, user_id int );
5. alter table review add CONSTRAINT fk_review_music FOREIGN key (music_id) REFERENCES music(id);
6. alter table review add CONSTRAINT fk_review_user FOREIGN key (user_id) REFERENCES user(id);
7. create table user( username varchar(16) unique, image varchar(64), signature varchar(64), nickname varchar(16), id int primary key );
8. create table music_user( id int PRIMARY key, music_id int, user_id int );
9. alter table music_user add CONSTRAINT fk_music_user_music FOREIGN key (music_id) REFERENCES music(id);
10. alter table music_user add CONSTRAINT fk_music_user_user FOREIGN key (user_id) REFERENCES user(id);

相關文章