0% found this document useful (0 votes)
7 views4 pages

CORRECTION TP3 Script - Bdville

The document outlines the creation and management of a relational database named 'bdVille', which includes tables for countries (PAYS) and cities (VILLE) with relevant attributes and foreign key relationships. It details the addition of filegroups, files, and partitioning schemes to optimize data storage and access. Additionally, it includes SQL commands for inserting data into the tables and managing database properties such as auto-shrink and file space usage.

Uploaded by

Angélica DEKE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

CORRECTION TP3 Script - Bdville

The document outlines the creation and management of a relational database named 'bdVille', which includes tables for countries (PAYS) and cities (VILLE) with relevant attributes and foreign key relationships. It details the addition of filegroups, files, and partitioning schemes to optimize data storage and access. Additionally, it includes SQL commands for inserting data into the tables and managing database properties such as auto-shrink and file space usage.

Uploaded by

Angélica DEKE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

--MODELE RELATIONNEL

--PAYS(codePays PK CHAR(3),
-- nomPays CHAR (40)
-- )

--VILLE(codeVille CHAR (3),


-- nomVille VARCHAR (40),
-- codePays ==> PAYS
-- )

--Q1

EXEC SP_HELPDB 'bdVille';

CREATE DATABASE bdVille


ON PRIMARY (
NAME = 'bdVille',
FILENAME = 'C:\DONNES\ville\bdVille.mdf',
SIZE = 10MB,
MAXSIZE = 100MB,
FILEGROWTH = 10MB
)
LOG ON (
NAME = 'bdVille_log',
FILENAME = 'C:\DONNES\ville\bdVille_log.ldf',
SIZE = 8MB,
MAXSIZE = 1GB,
FILEGROWTH = 25%
);

--Q2

ALTER DATABASE bdVille


ADD FILEGROUP gfVille1;

ALTER DATABASE bdVille


ADD FILEGROUP gfVille2;

ALTER DATABASE bdVille


ADD FILEGROUP gfVille3;

ALTER DATABASE bdVille


ADD FILEGROUP gfVille4;

ALTER DATABASE bdVille


ADD FILEGROUP gfPays;

--Q3

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville11',
FILENAME = 'C:\DONNES\ville\ville11.ndf'

) TO FILEGROUP gfVille1;
ALTER DATABASE bdVille
ADD FILE (
NAME = 'ville12',
FILENAME = 'C:\DONNES\ville\ville12.ndf'

) TO FILEGROUP gfVille1;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville21',
FILENAME = 'C:\DONNES\ville\ville21.ndf'

) TO FILEGROUP gfVille2;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville22',
FILENAME = 'C:\DONNES\ville\ville22.ndf'
) TO FILEGROUP gfVille2;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville31',
FILENAME = 'C:\DONNES\ville\ville31.ndf'

) TO FILEGROUP gfVille3;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville32',
FILENAME = 'C:\DONNES\ville\ville32.ndf'
) TO FILEGROUP gfVille3;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville41',
FILENAME = 'C:\DONNES\ville\ville41.ndf'
) TO FILEGROUP gfVille4;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'ville42',
FILENAME = 'C:\DONNES\ville\ville42.ndf'
) TO FILEGROUP gfVille4;

ALTER DATABASE bdVille


ADD FILE (
NAME = 'pays1',
FILENAME = 'C:\DONNES\ville\pays1.ndf'
) ,
(
NAME = 'pays2',
FILENAME = 'C:\DONNES\ville\pays2.ndf'
) TO FILEGROUP gfPays;

--connaitre les details des fichiers


USE bdVille;
SELECT * FROM SYS.database_files ;
--connaitre les details des blocs
SELECT * FROM SYS.dm_db_file_space_usage ;

--Jointure sur les 2 tables


SELECT table2.FILE_ID, table2.name, table1.total_page_count,
table1.allocated_extent_page_count,
table1.unallocated_extent_page_count
FROM SYS.dm_db_file_space_usage AS table1
INNER JOIN SYS.database_files AS table2 ON table1.FILE_id = table2.FILE_id ;

--Q4

SELECT name
FROM sys.filegroups
WHERE name = 'gfPays';

--Q5

ALTER DATABASE bdVille


SET AUTO_SHRINK ON;

SELECT * FROM SYS.databases;

--Q6

CREATE TABLE PAYS (


codePays CHAR(2) PRIMARY KEY,
nomPays VARCHAR(100)
) ON gfPays;

--Q7

CREATE PARTITION FUNCTION pfVille (CHAR(2))


AS RANGE LEFT FOR VALUES ('JA','QA');

--Q8

CREATE PARTITION SCHEME schemaVille


AS PARTITION pfVille
TO (gfVille1,gfVille2,gfVille3,gfVille4);

--Q9

CREATE TABLE VILLE (


codeVille INT IDENTITY(1,1), --AUTO INCREMENT
nomVille VARCHAR(40),
codePays CHAR(2),
constraint fk_Ville_Pays foreign key (codePays)
references Pays (codePays)

) ON schemaVille (codePays);

EXEC SP_HELP 'PAYS';

EXEC SP_HELP 'VILLE';

EXEC SP_SPACEUSED'PAYS';

--INSERTION

INSERT INTO PAYS VALUES(


'TG',
'TOGO'
), (
'CI',
'COTE D''IVOIRE'
);

INSERT INTO VILLE (nomVille, codePays) VALUES (

'Lome',
'TG'
);

INSERT INTO VILLE (nomVille, codePays) VALUES (

'Kara',
'TG'
),(

'Ndjamena',
'TG'
);

INSERT INTO VILLE (nomVille, codePays) VALUES (

'BABI',
'CI'
);

INSERT INTO PAYS VALUES(


'ZB',
'ZAMBIE'
);

INSERT INTO VILLE (nomVille, codePays) VALUES (


'Kabwe',
'ZB'
);

INSERT INTO PAYS VALUES(


'RW',
'RWANDA'
);

ALTER PARTITION FUNCTION pfVille () SPLIT


RANGE ('SA');

-- C'EST TOUJOURS BIEN FAIT

You might also like