notebook/IT/SQL/SCRIPTS SQL QSA ORSYS/Solution exo 1 stockage.sql
2020-11-26 18:38:25 +01:00

146 lines
13 KiB
Transact-SQL

ALTER DATABASE [DB_GRAND_HOTEL] ADD FILEGROUP FG_DATA;
GO
ALTER DATABASE [DB_GRAND_HOTEL]
ADD FILE (NAME = 'F_DATA_1',
FILENAME = 'H:\DATABASE_SQL\SQL2019FBIN2\DATA\F_DATA_1.ndf',
SIZE = 100 MB,
FILEGROWTH = 64 MB)
TO FILEGROUP FG_DATA;
GO
ALTER DATABASE [DB_GRAND_HOTEL]
ADD FILE (NAME = 'F_DATA_2',
FILENAME = 'H:\DATABASE_SQL\SQL2019FBIN2\DATA\F_DATA_2.ndf',
SIZE = 100 MB,
FILEGROWTH = 64 MB)
TO FILEGROUP FG_DATA;
GO
ALTER DATABASE [DB_GRAND_HOTEL]
MODIFY FILEGROUP FG_DATA DEFAULT;
GO
--> déplacement des tables et index
USE [DB_GRAND_HOTEL]
GO
CREATE UNIQUE CLUSTERED INDEX [PK_T_ADRESSE_ADR] ON [S_PRS].[T_ADRESSE_ADR] ([ADR_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_ADRPAY_FK] ON [S_PRS].[T_ADRESSE_ADR] ([PAY_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [SITUE__ADR__FK] ON [S_PRS].[T_ADRESSE_ADR] ([STT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [ADR_DEFAUT2_FK] ON [S_PRS].[T_ADRESSE_ADR] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_CHAMBRE_CHB] ON [S_CHB].[T_CHAMBRE_CHB] ([CHB_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_CLIENT_CLI] ON [S_CEE].[T_CLIENT_CLI] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_DNS] ON [S_PRS].[T_DNS] ([DNS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_DNS_NAME] ON [S_PRS].[T_DNS] ([DNS_NAME] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_EMAIL_EML] ON [S_PRS].[T_EMAIL_EML] ([EML_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_EMLSTT_FK] ON [S_PRS].[T_EMAIL_EML] ([STT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [LOCALISE_FK] ON [S_PRS].[T_EMAIL_EML] ([DNS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [MAIL_DEFAUT_FK] ON [S_PRS].[T_EMAIL_EML] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_EMPLOYE_EMP] ON [S_CEE].[T_EMPLOYE_EMP] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [AK_UK_EMP_MAT_T_EMPLOY] ON [S_CEE].[T_EMPLOYE_EMP] ([EMP_NATRICULE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [ASSOCIATION_21_FK] ON [S_CEE].[T_EMPLOYE_EMP] ([SVC_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [ASSOCIATION_22_FK] ON [S_CEE].[T_EMPLOYE_EMP] ([T_E_PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [INVESTI_FK] ON [S_CEE].[T_EMPLOYE_EMP] ([FCT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_FACTURE_FAC] ON [S_CHB].[T_FACTURE_FAC] ([FAC_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [PAYE_FK] ON [S_CHB].[T_FACTURE_FAC] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [PAYEE_FK] ON [S_CHB].[T_FACTURE_FAC] ([PMT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_FACTURE_ITEM_ITM] ON [S_CHB].[T_FACTURE_ITEM_ITM] ([ITM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [CONTIENT_FK] ON [S_CHB].[T_FACTURE_ITEM_ITM] ([FAC_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TAXE_FK] ON [S_CHB].[T_FACTURE_ITEM_ITM] ([TVA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_J_APPLIQUE_APQ] ON [S_CLD].[T_J_APPLIQUE_APQ] ([PFM_ID] ASC, [PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPFM_FK] ON [S_CLD].[T_J_APPLIQUE_APQ] ([PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_J_TRAVAILLE_TRV] ON [S_CEE].[T_J_TRAVAILLE_TRV] ([PRS_ID] ASC, [PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [T_J_TRAVAILLE_TRV2_FK] ON [S_CEE].[T_J_TRAVAILLE_TRV] ([PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_LIGNE_ADRESSE_LAD] ON [S_PRS].[T_LIGNE_ADRESSE_LAD] ([LAD_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [COMPOSEE_FK] ON [S_PRS].[T_LIGNE_ADRESSE_LAD] ([ADR_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_MANDATAIRE_MDT] ON [S_CEE].[T_MANDATAIRE_MDT] ([MDT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [EST_MANDATEE_FK] ON [S_CEE].[T_MANDATAIRE_MDT] ([T_P_PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [REPRESENTEE_FK] ON [S_CEE].[T_MANDATAIRE_MDT] ([PRS_ID_MORALE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [ASSOCIATION_20_FK] ON [S_CEE].[T_MANDATAIRE_MDT] ([MDA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_OCCUPATION_OCP] ON [S_CHB].[T_OCCUPATION_OCP] ([CHB_ID] ASC, [PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [OCCUPEE_FK] ON [S_CHB].[T_OCCUPATION_OCP] ([PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [PAR_FK] ON [S_CHB].[T_OCCUPATION_OCP] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_PERSONNE_MORALE_PSM] ON [S_PRS].[T_PERSONNE_MORALE_PSM] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [DOTEE_FK] ON [S_PRS].[T_PERSONNE_MORALE_PSM] ([FMO_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_PERSONNE_PHYSIQUE_PSP] ON [S_PRS].[T_PERSONNE_PHYSIQUE_PSP] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_ATRTIT_FK] ON [S_PRS].[T_PERSONNE_PHYSIQUE_PSP] ([TIT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_ATRSEX_FK] ON [S_PRS].[T_PERSONNE_PHYSIQUE_PSP] ([SEX_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_PERSONNE_PRS] ON [S_PRS].[T_PERSONNE_PRS] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [ADR_DEFAUT_FK] ON [S_PRS].[T_PERSONNE_PRS] ([ADR_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [MAIL_DEFAUT2_FK] ON [S_PRS].[T_PERSONNE_PRS] ([EML_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TEL_DEFAUT2_FK] ON [S_PRS].[T_PERSONNE_PRS] ([TEL_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_PLN_JOUR_PJR] ON [S_CLD].[T_PLN_JOUR_PJR] ([PJR_DATE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPJM_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PJM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPMS_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PMS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPAN_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PAN_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_PJRPSM_DEBUTE_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PSM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPJS_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PJS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_PJRPJA_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PJA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPTR_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PTR_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJRPST_FK1] ON [S_CLD].[T_PLN_JOUR_PJR] ([PST_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_RESERVATION_RSV] ON [S_CHB].[T_RESERVATION_RSV] ([RSV_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [DEMANDE_FK] ON [S_CHB].[T_RESERVATION_RSV] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [SEJOUR_DEBUTE_FK] ON [S_CHB].[T_RESERVATION_RSV] ([PJR_DATE_DEBUTE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [SEJOUR_TERMINE_FK] ON [S_CHB].[T_RESERVATION_RSV] ([PJR_DATE_FINIE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_FONCTION_FCT] ON [S_CEE].[T_R_FONCTION_FCT] ([FCT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_FCT_CODE] ON [S_CEE].[T_R_FONCTION_FCT] ([FCT_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_FORME_ORGANISATION_FMO] ON [S_PRS].[T_R_FORME_ORGANISATION_FMO] ([FMO_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_FMO_CODE] ON [S_PRS].[T_R_FORME_ORGANISATION_FMO] ([FMO_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UQ__DUAL__395884C4] ON [dbo].[DUAL] ([C] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_MANDAT_MDA] ON [S_CEE].[T_R_MANDAT_MDA] ([MDA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_MDA_CODE] ON [S_CEE].[T_R_MANDAT_MDA] ([MDA_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_MODE_PAIEMENT_PMT] ON [S_CHB].[T_R_MODE_PAIEMENT_PMT] ([PMT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_PMT_CODE] ON [S_CHB].[T_R_MODE_PAIEMENT_PMT] ([PMT_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PAYS_PAY] ON [S_PRS].[T_R_PAYS_PAY] ([PAY_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_PAY_CODE] ON [S_PRS].[T_R_PAYS_PAY] ([PAY_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_ANNEE_PAN] ON [S_CLD].[T_R_PLN_ANNEE_PAN] ([PAN_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_JOUR_ANNEE_PJA] ON [S_CLD].[T_R_PLN_JOUR_ANNEE_PJA] ([PJA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_JOUR_FERIE_FIXE_PJF] ON [S_CLD].[T_R_PLN_JOUR_FERIE_FIXE_PJF] ([PJM_ID] ASC, [PMS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [L_PJFPMS_FK] ON [S_CLD].[T_R_PLN_JOUR_FERIE_FIXE_PJF] ([PMS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_JOUR_FERIE_MOBILE_P] ON [S_CLD].[T_R_PLN_JOUR_FERIE_MOBILE_PFM] ([PFM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_JOUR_MOIS_PJM] ON [S_CLD].[T_R_PLN_JOUR_MOIS_PJM] ([PJM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_JOUR_SEMAINE_PJS] ON [S_CLD].[T_R_PLN_JOUR_SEMAINE_PJS] ([PJS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_MOIS_PMS] ON [S_CLD].[T_R_PLN_MOIS_PMS] ([PMS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_SEMAINE_PSM] ON [S_CLD].[T_R_PLN_SEMAINE_PSM] ([PSM_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_SEMESTRE_PST] ON [S_CLD].[T_R_PLN_SEMESTRE_PST] ([PST_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_PLN_TRIMESTRE_PTR] ON [S_CLD].[T_R_PLN_TRIMESTRE_PTR] ([PTR_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_SERVICE_SCV] ON [S_CEE].[T_R_SERVICE_SCV] ([SVC_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_SEXE_SEX] ON [S_PRS].[T_R_SEXE_SEX] ([SEX_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_SEX_CODE] ON [S_PRS].[T_R_SEXE_SEX] ([SEX_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_SITUATION_STT] ON [S_PRS].[T_R_SITUATION_STT] ([STT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_STT_CODE] ON [S_PRS].[T_R_SITUATION_STT] ([STT_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_TITRE_TIT] ON [S_PRS].[T_R_TITRE_TIT] ([TIT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_TIT_CODE] ON [S_PRS].[T_R_TITRE_TIT] ([TIT_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_R_TYPE_TELEPHONE_TTL] ON [S_PRS].[T_R_TYPE_TELEPHONE_TTL] ([TTL_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE INDEX [UK_TTL_CODE] ON [S_PRS].[T_R_TYPE_TELEPHONE_TTL] ([TTL_CODE] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_TELEPHONE_TEL] ON [S_PRS].[T_TELEPHONE_TEL] ([TEL_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_TELSTT_FK] ON [S_PRS].[T_TELEPHONE_TEL] ([STT_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TJ_TELTTL_FK] ON [S_PRS].[T_TELEPHONE_TEL] ([TTL_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE INDEX [TEL_DEFAUT_FK] ON [S_PRS].[T_TELEPHONE_TEL] ([PRS_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
CREATE UNIQUE CLUSTERED INDEX [PK_T_TVA] ON [S_CHB].[T_TVA] ([TVA_ID] ASC) WITH (DROP_EXISTING = ON) ON FG_DATA;
GO
ALTER TABLE [dbo].[DUAL] ADD _ INT IDENTITY NOT NULL CONSTRAINT UKsupertoto UNIQUE CLUSTERED ON FG_DATA;ALTER TABLE [dbo].[DUAL] DROP CONSTRAINT UKsupertoto;ALTER TABLE [dbo].[DUAL] DROP COLUMN _;
GO
-- redimensionnement des fichiers journal et mdf
USE [DB_GRAND_HOTEL]
GO
DBCC SHRINKFILE (N'DB_GRAND_HOTEL' , 10)
GO
USE [master]
GO
ALTER DATABASE [DB_GRAND_HOTEL]
MODIFY FILE ( NAME = N'DB_GRAND_HOTEL_log',
SIZE = 102400KB )
GO
-- retaillage du pas d'incrément des fichiers journal et mdf
USE [master]
GO
ALTER DATABASE [DB_GRAND_HOTEL]
MODIFY FILE ( NAME = N'DB_GRAND_HOTEL',
FILEGROWTH = 10240KB )
GO
ALTER DATABASE [DB_GRAND_HOTEL]
MODIFY FILE ( NAME = N'DB_GRAND_HOTEL_log',
FILEGROWTH = 65536KB )
GO