-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseDatos.sql
More file actions
77 lines (64 loc) · 2.34 KB
/
BaseDatos.sql
File metadata and controls
77 lines (64 loc) · 2.34 KB
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
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);
END;
GO
BEGIN TRANSACTION;
GO
CREATE TABLE [Clientes] (
[ClienteId] int NOT NULL IDENTITY,
[Contrasena] nvarchar(100) NOT NULL,
[Estado] bit NOT NULL DEFAULT CAST(1 AS bit),
[Nombre] nvarchar(100) NOT NULL,
[Genero] nvarchar(20) NOT NULL,
[Edad] int NOT NULL,
[Identificacion] nvarchar(20) NOT NULL,
[Direccion] nvarchar(200) NOT NULL,
[Telefono] nvarchar(20) NOT NULL,
CONSTRAINT [PK_Clientes] PRIMARY KEY ([ClienteId])
);
GO
CREATE TABLE [Cuentas] (
[CuentaId] int NOT NULL IDENTITY,
[NumeroCuenta] nvarchar(20) NOT NULL,
[TipoCuenta] nvarchar(50) NOT NULL,
[SaldoInicial] decimal(18,2) NOT NULL,
[Estado] bit NOT NULL DEFAULT CAST(1 AS bit),
[ClienteId] int NOT NULL,
CONSTRAINT [PK_Cuentas] PRIMARY KEY ([CuentaId]),
CONSTRAINT [FK_Cuentas_Clientes_ClienteId] FOREIGN KEY ([ClienteId]) REFERENCES [Clientes] ([ClienteId]) ON DELETE NO ACTION
);
GO
CREATE TABLE [Movimientos] (
[MovimientoId] int NOT NULL IDENTITY,
[Fecha] datetime2 NOT NULL DEFAULT (GETDATE()),
[TipoMovimiento] nvarchar(20) NOT NULL,
[Valor] decimal(18,2) NOT NULL,
[Saldo] decimal(18,2) NOT NULL,
[Estado] bit NOT NULL DEFAULT CAST(1 AS bit),
[CuentaId] int NOT NULL,
CONSTRAINT [PK_Movimientos] PRIMARY KEY ([MovimientoId]),
CONSTRAINT [FK_Movimientos_Cuentas_CuentaId] FOREIGN KEY ([CuentaId]) REFERENCES [Cuentas] ([CuentaId]) ON DELETE NO ACTION
);
GO
CREATE UNIQUE INDEX [IX_Clientes_Identificacion] ON [Clientes] ([Identificacion]);
GO
CREATE INDEX [IX_Cuentas_ClienteId] ON [Cuentas] ([ClienteId]);
GO
CREATE UNIQUE INDEX [IX_Cuentas_NumeroCuenta] ON [Cuentas] ([NumeroCuenta]);
GO
CREATE INDEX [IX_Movimientos_Cuenta_Fecha] ON [Movimientos] ([CuentaId], [Fecha]);
GO
CREATE INDEX [IX_Movimientos_Cuenta_Fecha_Tipo] ON [Movimientos] ([CuentaId], [Fecha], [TipoMovimiento]) WHERE [TipoMovimiento] = 'Debito';
GO
CREATE INDEX [IX_Movimientos_Fecha] ON [Movimientos] ([Fecha]);
GO
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20251101022510_InitialCreate', N'8.0.11');
GO
COMMIT;
GO