-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQLQuery10.sql
47 lines (36 loc) · 1.43 KB
/
SQLQuery10.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
CREATE TABLE [dbo].[Cliente] (
[Id] INT IDENTITY(1,1) NOT NULL,
[Nombres] VARCHAR (MAX) NOT NULL,
[Correo] VARCHAR (MAX) NOT NULL,
[Clave] VARCHAR (max) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Producto] (
[Id] INT IDENTITY(1,1) NOT NULL,
[Nombre] VARCHAR (max) NOT NULL,
[Precio] FLOAT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Estado] (
[Id] INT IDENTITY(1,1) NOT NULL,
[Nombre] VARCHAR (MAX) NOT NULL,
CONSTRAINT [PK_Estado] PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Pedido] (
[Id] INT IDENTITY(1,1) NOT NULL,
[ClienteId] INT NOT NULL,
[EstadoId] INT NOT NULL,
[FechaPedido] DATETIME DEFAULT (getdate()) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Pedido_ClienteId] FOREIGN KEY ([ClienteId]) REFERENCES [dbo].[Cliente] ([Id]),
CONSTRAINT [FK_Estado_EstadoId] FOREIGN KEY ([EstadoId]) REFERENCES [dbo].[Estado] ([Id])
);
CREATE TABLE [dbo].[DetallePedido] (
[Id] INT IDENTITY(1,1) NOT NULL ,
[PedidoId] INT NOT NULL,
[ProductoId] INT NOT NULL,
[Cantidad] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Pedido_PedidoId] FOREIGN KEY ([PedidoId]) REFERENCES [dbo].[Pedido] ([Id]),
CONSTRAINT [FK_Producto_ProductoId] FOREIGN KEY ([ProductoId]) REFERENCES [dbo].[Producto] ([Id])
);