-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLStock.sql
120 lines (108 loc) · 4.01 KB
/
SQLStock.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
DROP TABLE LigneAppro;
DROP TABLE LigneApproAutreStock;
DROP TABLE ProduitAutreStock;
DROP TABLE LigneUtilisation;
DROP TABLE SortieAutreStock;
DROP TABLE SortiePharma;
--Créer
CREATE TABLE [dbo].[LigneCommande] (
[idcom] INT NOT NULL,
[date_com] DATE NOT NULL,
[idstock] INT NOT NULL,
[qtedem] SMALLINT NOT NULL,
PRIMARY KEY CLUSTERED ([idcom] ASC),
FOREIGN KEY ([idstock]) REFERENCES [dbo].[LigneStock] ([idstock])
);
CREATE TABLE [dbo].[CategorieProduit] (
[idcat] SMALLINT NOT NULL,
[categorie] VARCHAR(30) NOT NULL,
PRIMARY KEY CLUSTERED ([idcat] ASC),
);
--Recréer
CREATE TABLE [dbo].[Pharmacie] (
[idpharma] SMALLINT NOT NULL,
[designation] VARCHAR(30) NOT NULL,
PRIMARY KEY CLUSTERED ([idpharma] ASC)
);
CREATE TABLE [dbo].[LigneStock] (
[idstock] INT NOT NULL,
[idproduit] SMALLINT NOT NULL,
[qtestock] INT NOT NULL,
[CMM] INT NOT NULL,
[forme] VARCHAR (15) NOT NULL,
[dosage] VARCHAR (20) NULL,
[numlot] VARCHAR (20) NULL,
[expiration] VARCHAR (10) NULL,
[prixunitaire] NUMERIC (12, 2) NULL,
[prix_abonne] NUMERIC (12, 2) NULL,
PRIMARY KEY CLUSTERED ([idstock] ASC),
FOREIGN KEY ([idproduit]) REFERENCES [dbo].[Produit] ([idproduit])
);
CREATE TABLE [dbo].[Produit] (
[idproduit] SMALLINT NOT NULL,
[nomproduit] VARCHAR (50) NOT NULL,
[idcat] SMALLINT NOT NULL,
PRIMARY KEY CLUSTERED ([idproduit] ASC)
FOREIGN KEY ([idcat]) REFERENCES [dbo].[CategorieProduit] ([idcat])
);
CREATE TABLE [dbo].[LigneStockPharma] (
[idstockph] INT NOT NULL,
[idpharma] SMALLINT NOT NULL,
[idstock] INT NOT NULL,
[qtestock] INT NOT NULL,
PRIMARY KEY CLUSTERED ([idstockph] ASC),
FOREIGN KEY ([idstock]) REFERENCES [dbo].[LigneStock] ([idstock]),
FOREIGN KEY ([idpharma]) REFERENCES [dbo].[Pharmacie] ([idpharma])
);
CREATE TABLE [dbo].[LigneAppro] (
[idappro] INT NOT NULL,
[date_appro] DATE NOT NULL,
[idcom] INT NOT NULL,
[qteappro] SMALLINT NOT NULL,
[qteajoute] SMALLINT NOT NULL,
[prix_achat] NUMERIC (12, 2) NULL,
[taux] NUMERIC (5, 2) NULL,
[observation] varchar (100) NULL,
PRIMARY KEY CLUSTERED ([idappro] ASC),
FOREIGN KEY ([idcom]) REFERENCES [dbo].[LigneCommande] ([idcom])
);
--Recréer
CREATE TABLE [dbo].[CommandePharma] (
[idcomph] INT NOT NULL,
[idstockph] INT NOT NULL,
[date_com] DATE NOT NULL,
[qtecom] SMALLINT NOT NULL,
PRIMARY KEY CLUSTERED ([idcomph] ASC),
FOREIGN KEY ([idstockph]) REFERENCES [dbo].[LigneStockPharma] ([idstockph])
);
CREATE TABLE [dbo].[ApproPharma] (
[idapproph] INT NOT NULL,
[date_appro] DATE NOT NULL,
[idcomph] INT NOT NULL,
[qteservie] SMALLINT NOT NULL,
PRIMARY KEY CLUSTERED ([idapproph] ASC),
FOREIGN KEY ([idcomph]) REFERENCES [dbo].[CommandePharma] ([idcomph])
);
CREATE TABLE [dbo].[SortiePharma] (
[idsortie] INT NOT NULL,
[date_jour] SMALLDATETIME NOT NULL,
[idstockph] INT NOT NULL,
[qte_dem] SMALLINT NOT NULL,
[qteservie] SMALLINT NOT NULL,
[motif] VARCHAR (30) NOT NULL,
[idposte] SMALLINT NULL,
PRIMARY KEY CLUSTERED ([idsortie] ASC),
FOREIGN KEY ([idstockph]) REFERENCES [dbo].[LigneStockPharma] ([idstockph])
);
--créer
CREATE TABLE [dbo].[SortieStock] (
[idsortie] INT NOT NULL,
[date_jour] SMALLDATETIME NOT NULL,
[idstock] INT NOT NULL,
[qte_dem] SMALLINT NOT NULL,
[qteservie] SMALLINT NOT NULL,
[motif] VARCHAR (30) NOT NULL,
[idposte] SMALLINT NULL,
PRIMARY KEY CLUSTERED ([idsortie] ASC),
FOREIGN KEY ([idstock]) REFERENCES [dbo].[LigneStock] ([idstock])
);