-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexa 1.sql
146 lines (117 loc) · 3.06 KB
/
exa 1.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
if db_id('BDBackus ')is not null
drop database BDBackus
go
create database BDBackus
on
(name = Backus_Data, filename='C:\Exam\Backus_Data.MDF'
,size=18MB, maxsize=90MB, filegrowth=20MB)
log on
(name=Backus_Log, filename='C:\Exam\Backus_Log.LDF',
size=10MB, maxsize=210MB, filegrowth=35%)
go
-----------------------------------------
alter database BDBackus
add filegroup FGBackus01
go
alter database BDBackus
add filegroup FGBackus02
go
alter database BDBackus
add filegroup FGBackus03
go
--------------------------------------
Alter DataBase BDBackus
Add File
(name=Backus_DataN1, filename='C:\Eval\Backus_DataN1.NDF')
to filegroup FGBackus01
go
Alter DataBase BDBackus
Add File
(name=Backus_DataN2, filename='C:\Eval\Backus_DataN2.NDF')
to filegroup FGBackus02
go
Alter DataBase BDBackus
Add File
(name=Backus_DataN3, filename='C:\Eval\Backus_DataN3.NDF')
to filegroup FGBackus03
go
-------------------------------------------
create schema COMP
go
create schema VENT
go
----------------------------------
create table Usuario(
TD_VC varchar(50) not null,
TD_NU numeric(16,4) null,
TD_IN int not null
)
go
---------------------------------
create table VENT.Proveedor(
IdProveedor char(5) not null,
NombreProveedor varchar(50)not null,
Direccion varchar(50) not null,
Ciudad varchar(50) not null,
Pais varchar(50) not null,
telefono varchar(12)not null
constraint PKProveedor primary key(IdProveedor)
)on FGBackus01
go
create table VENT.Categoria(
IdCategoria char(5)not null,
NombreCategoria varchar(50) not null,
constraint PKCategoria primary key(IdCategoria)
)on FGBackus01
go
create table VENT.Producto(
IdProducto char(5) not null,
NombreProducto varchar(50)not null,
IdProveedor char(5) not null,
IdCategoria char(5)not null,
CantidadPorUnidad int not null,
PrecioUnidad money not null,
UnidadesEnexistencia varchar(50) not null,
constraint PKProducto primary key(IdProducto),
constraint FKIdProveedor foreign key (IdProveedor) references VENT.Proveedor,
constraint FKIdCategoria foreign key (IdCategoria) references VENT.Categoria
)on FGBackus01
go
---------------------------------------
alter table VENT.Producto
add constraint CKPrecioUnidad check (PrecioUnidad >= 20),
constraint CKUnidadesEnexistencia check (UnidadesEnexistencia >= 30)
go
--------------------------------------------
create partition function fnpPedidos(int)
as range left for values (10400 ,10800 )
go
create partition scheme scpGenerados
as partition fnpPedidos to([FGBackus01],[FGBackus02],[FGBackus03])
go
create table VENT.Pedido(
idPedi int not null,
FecPedi datetime,
Pais VarChar(50)
) on scpGenerados(idPedi)
go
insert VENT.Pedido
values
(1000,GETDATE(), 'Canada'),
(1020,GETDATE(), 'Peru'),
(2100,GETDATE(), 'Brazil'),
(4000,GETDATE(), 'Argentina'),
(4500,GETDATE(), 'Ecuador'),
(8000,GETDATE(), 'Japon')
go
---------------------------
select * ,
$partition.fnpPedidos(idPedi) as [Pedido]
from VENT.Pedido
go
create unique index idxNombreProveedor on VENT.Proveedor(NombreProveedor)
go
create unique index idxDireccion on VENT.Proveedor(Direccion)
go
create unique index idxPais on VENT.Proveedor(Pais)
go