From b209ca11d1aabbad922b606a17c1b7319502c989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=95=8F?= <3234934487@qq.com> Date: Wed, 13 Sep 2023 12:40:41 +0800 Subject: [PATCH] zy --- .../20290913 \347\224\265\345\275\261.md" | 416 ++++++++++++++++++ 1 file changed, 416 insertions(+) create mode 100644 "56 \350\265\265\346\225\217/20290913 \347\224\265\345\275\261.md" diff --git "a/56 \350\265\265\346\225\217/20290913 \347\224\265\345\275\261.md" "b/56 \350\265\265\346\225\217/20290913 \347\224\265\345\275\261.md" new file mode 100644 index 0000000..5ad00db --- /dev/null +++ "b/56 \350\265\265\346\225\217/20290913 \347\224\265\345\275\261.md" @@ -0,0 +1,416 @@ +作业 + +```MySQL +/*==============================================================*/ +/* DBMS name: Sybase SQL Anywhere 12 */ +/* Created on: 2023/9/13 9:34:30 */ +/*==============================================================*/ + + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_MOVIE') then + alter table Relationship_1 + delete foreign key FK_RELATION_RELATIONS_MOVIE +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_WEBSITE') then + alter table Relationship_1 + delete foreign key FK_RELATION_RELATIONS_WEBSITE +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_CREW') then + alter table Relationship_3 + delete foreign key FK_RELATION_RELATIONS_CREW +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_MAIN') then + alter table Relationship_3 + delete foreign key FK_RELATION_RELATIONS_MAIN +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_WEBSITE') then + alter table Relationship_4 + delete foreign key FK_RELATION_RELATIONS_WEBSITE +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_RELATION_RELATIONS_USER') then + alter table Relationship_4 + delete foreign key FK_RELATION_RELATIONS_USER +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_MAIN_RELATIONS_MOVIE') then + alter table main + delete foreign key FK_MAIN_RELATIONS_MOVIE +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_VIEW_RELATIONS_USER') then + alter table "view" + delete foreign key FK_VIEW_RELATIONS_USER +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_VIEW_RELATIONS_MOVIE') then + alter table "view" + delete foreign key FK_VIEW_RELATIONS_MOVIE +end if; + +drop index if exists Relationship_1.Relationship_1_FK; + +drop index if exists Relationship_1.Relationship_7_FK; + +drop index if exists Relationship_1.Relationship_1_PK; + +drop table if exists Relationship_1; + +drop index if exists Relationship_3.Relationship_3_FK; + +drop index if exists Relationship_3.Relationship_8_FK; + +drop index if exists Relationship_3.Relationship_3_PK; + +drop table if exists Relationship_3; + +drop index if exists Relationship_4.Relationship_4_FK; + +drop index if exists Relationship_4.Relationship_9_FK; + +drop index if exists Relationship_4.Relationship_4_PK; + +drop table if exists Relationship_4; + +drop index if exists crew.crew_PK; + +drop table if exists crew; + +drop index if exists main.Relationship_2_FK; + +drop index if exists main.main_PK; + +drop table if exists main; + +drop index if exists movie.movie_PK; + +drop table if exists movie; + +drop index if exists "user".user_PK; + +drop table if exists "user"; + +drop index if exists "view".Relationship_6_FK; + +drop index if exists "view".Relationship_5_FK; + +drop table if exists "view"; + +drop index if exists website.website_PK; + +drop table if exists website; + +if exists(select 1 from sys.syssequence s + where sequence_name='S_crew') then + drop sequence S_crew +end if; + +if exists(select 1 from sys.syssequence s + where sequence_name='S_main') then + drop sequence S_main +end if; + +if exists(select 1 from sys.syssequence s + where sequence_name='S_movie') then + drop sequence S_movie +end if; + +if exists(select 1 from sys.syssequence s + where sequence_name='S_user') then + drop sequence S_user +end if; + +create sequence S_crew; + +create sequence S_main; + +create sequence S_movie; + +create sequence S_user; + +/*==============================================================*/ +/* Table: Relationship_1 */ +/*==============================================================*/ + +create database z charset utf8; +use z; +create table Relationship_1 +( + mo_id integer not null, + we_id char(10) not null, + constraint PK_RELATIONSHIP_1 primary key (mo_id, we_id) +); + +/*==============================================================*/ +/* Index: Relationship_1_PK */ +/*==============================================================*/ +create unique index Relationship_1_PK on Relationship_1 ( +mo_id ASC, +we_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_7_FK */ +/*==============================================================*/ +create index Relationship_7_FK on Relationship_1 ( +we_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_1_FK */ +/*==============================================================*/ +create index Relationship_1_FK on Relationship_1 ( +mo_id ASC +); + +/*==============================================================*/ +/* Table: Relationship_3 */ +/*==============================================================*/ +create table Relationship_3 +( + cr_id integer not null, + main_id integer not null, + constraint PK_RELATIONSHIP_3 primary key (cr_id, main_id) +); + +/*==============================================================*/ +/* Index: Relationship_3_PK */ +/*==============================================================*/ +create unique index Relationship_3_PK on Relationship_3 ( +cr_id ASC, +main_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_8_FK */ +/*==============================================================*/ +create index Relationship_8_FK on Relationship_3 ( +main_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_3_FK */ +/*==============================================================*/ +create index Relationship_3_FK on Relationship_3 ( +cr_id ASC +); + +/*==============================================================*/ +/* Table: Relationship_4 */ +/*==============================================================*/ +create table Relationship_4 +( + we_id char(10) not null, + us_id integer not null, + constraint PK_RELATIONSHIP_4 primary key (we_id, us_id) +); + +/*==============================================================*/ +/* Index: Relationship_4_PK */ +/*==============================================================*/ +create unique index Relationship_4_PK on Relationship_4 ( +we_id ASC, +us_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_9_FK */ +/*==============================================================*/ +create index Relationship_9_FK on Relationship_4 ( +us_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_4_FK */ +/*==============================================================*/ +create index Relationship_4_FK on Relationship_4 ( +we_id ASC +); + +/*==============================================================*/ +/* Table: crew */ +/*==============================================================*/ +create table crew +( + cr_id integer not null default (S_crew.nextval), + cr_address varchar(225) not null, + cr_staff varchar(225) not null, + constraint PK_CREW primary key (cr_id) +); + +/*==============================================================*/ +/* Index: crew_PK */ +/*==============================================================*/ +create unique index crew_PK on crew ( +cr_id ASC +); + +/*==============================================================*/ +/* Table: main */ +/*==============================================================*/ +create table main +( + director varchar(10) not null, + scriptwriter varchar(10) not null, + Starring varchar(10) not null, + main_id integer not null default (S_main.nextval), + mo_id integer not null, + constraint PK_MAIN primary key (main_id) +); + +/*==============================================================*/ +/* Index: main_PK */ +/*==============================================================*/ +create unique index main_PK on main ( +main_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_2_FK */ +/*==============================================================*/ +create index Relationship_2_FK on main ( +mo_id ASC +); + +/*==============================================================*/ +/* Table: movie */ +/*==============================================================*/ +create table movie +( + mo_name varchar(20) not null, + mo_id integer not null default (S_movie.nextval), + mo_type varchar(225) not null, + mo_language varchar(225) not null, + datetime timestamp not null, + mo_time time not null, + constraint PK_MOVIE primary key (mo_id) +); + +/*==============================================================*/ +/* Index: movie_PK */ +/*==============================================================*/ +create unique index movie_PK on movie ( +mo_id ASC +); + +/*==============================================================*/ +/* Table: "user" */ +/*==============================================================*/ +create table "user" +( + us_id integer not null default (S_user.nextval), + us_name char(10) not null, + constraint PK_USER primary key (us_id) +); + +/*==============================================================*/ +/* Index: user_PK */ +/*==============================================================*/ +create unique index user_PK on "user" ( +us_id ASC +); + +/*==============================================================*/ +/* Table: "view" */ +/*==============================================================*/ +create table "view" +( + us_id integer not null, + mo_id integer not null, + vi_film char(255) null, + vi_short char(255) null +); + +/*==============================================================*/ +/* Index: Relationship_5_FK */ +/*==============================================================*/ +create index Relationship_5_FK on "view" ( +us_id ASC +); + +/*==============================================================*/ +/* Index: Relationship_6_FK */ +/*==============================================================*/ +create index Relationship_6_FK on "view" ( +mo_id ASC +); + +/*==============================================================*/ +/* Table: website */ +/*==============================================================*/ +create table website +( + we_id char(10) not null, + we_address char(10) not null, + we_name char(10) not null, + constraint PK_WEBSITE primary key (we_id) +); + +/*==============================================================*/ +/* Index: website_PK */ +/*==============================================================*/ +create unique index website_PK on website ( +we_id ASC +); + +alter table Relationship_1 + add constraint FK_RELATION_RELATIONS_MOVIE foreign key (mo_id) + references movie (mo_id) + on update restrict + on delete restrict; + +alter table Relationship_1 + add constraint FK_RELATION_RELATIONS_WEBSITE foreign key (we_id) + references website (we_id) + on update restrict + on delete restrict; + +alter table Relationship_3 + add constraint FK_RELATION_RELATIONS_CREW foreign key (cr_id) + references crew (cr_id) + on update restrict + on delete restrict; + +alter table Relationship_3 + add constraint FK_RELATION_RELATIONS_MAIN foreign key (main_id) + references main (main_id) + on update restrict + on delete restrict; + +alter table Relationship_4 + add constraint FK_RELATION_RELATIONS_WEBSITE foreign key (we_id) + references website (we_id) + on update restrict + on delete restrict; + +alter table Relationship_4 + add constraint FK_RELATION_RELATIONS_USER foreign key (us_id) + references "user" (us_id) + on update restrict + on delete restrict; + +alter table main + add constraint FK_MAIN_RELATIONS_MOVIE foreign key (mo_id) + references movie (mo_id) + on update restrict + on delete restrict; + +alter table "view" + add constraint FK_VIEW_RELATIONS_USER foreign key (us_id) + references "user" (us_id) + on update restrict + on delete restrict; + +alter table "view" + add constraint FK_VIEW_RELATIONS_MOVIE foreign key (mo_id) + references movie (mo_id) + on update restrict + on delete restrict; + + +``` + -- Gitee