This repository has been archived by the owner on Sep 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsignacion.sql
419 lines (337 loc) · 9.33 KB
/
Asignacion.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: cambiarNombre uncomitted
-- Otros detalles de los parametros
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[cambiarNombre] @Email NVARCHAR(50), @Nombre NVARCHAR(50) AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @InicieTransaccion BIT
DECLARE @IdUsuario INT
SELECT @IdUsuario=(SELECT IdUsuario FROM Usuarios WHERE Email=@Email)
IF (@IdUsuario IS NOT NULL)
BEGIN
SET @InicieTransaccion = 0
IF @@TRANCOUNT=0 BEGIN
SET @InicieTransaccion = 1
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
BEGIN TRANSACTION
END
BEGIN TRY
SET @CustomError = 2001
UPDATE Usuarios SET Nombre=@Nombre WHERE idUsuario=@IdUsuario
IF @InicieTransaccion=1 BEGIN
COMMIT
END
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
IF @InicieTransaccion=1 BEGIN
ROLLBACK
END
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
ELSE
BEGIN
PRINT 'Usuario incorrecto'
END
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Cambia el apellido de un usuario
-- Otros detalles de los parametros
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[cambiarApellido] @Email NVARCHAR(50), @Apellido NVARCHAR(50) AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @InicieTransaccion BIT
DECLARE @IdUsuario INT
SELECT @IdUsuario=(SELECT IdUsuario FROM Usuarios WHERE Email=@Email)
IF (@IdUsuario IS NOT NULL)
BEGIN
SET @InicieTransaccion = 0
IF @@TRANCOUNT=0 BEGIN
SET @InicieTransaccion = 1
BEGIN TRANSACTION
END
BEGIN TRY
SET @CustomError = 2001
UPDATE Usuarios SET Apellido1=@Apellido WHERE idUsuario=@IdUsuario
WAITFOR DELAY '00:00:08.000';
IF @InicieTransaccion=1 BEGIN
COMMIT
END
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
IF @InicieTransaccion=1 BEGIN
ROLLBACK
END
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
ELSE
BEGIN
PRINT 'Usuario incorrecto'
END
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/30/2014
-- Descripcion: ver Usuario
-- Otros detalles de los parametros
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[verUsuarios] AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @InicieTransaccion BIT
SET @InicieTransaccion = 0
IF @@TRANCOUNT=0 BEGIN
SET @InicieTransaccion = 1
BEGIN TRANSACTION
END
BEGIN TRY
SET @CustomError = 2001
SELECT * FROM Usuarios;
IF @InicieTransaccion=1 BEGIN
COMMIT
END
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
IF @InicieTransaccion=1 BEGIN
ROLLBACK
END
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Comitted
-- Otros detalles de los parametros
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[spCommit] @Email nvarchar(50) AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @IdUsuario bigint;
DECLARE @InicieTransaccion BIT
SELECT @IdUsuario =(SELECT IdUsuario FROM Usuarios WHERE Email=@Email)
IF (@IdUsuario IS NOT NULL)
BEGIN
SET @InicieTransaccion = 0
IF @@TRANCOUNT=0 BEGIN
SET @InicieTransaccion = 1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN TRANSACTION
END
BEGIN TRY
SET @CustomError = 2001
SELECT * FROM Usuarios WHERE idUsuario=@IdUsuario
IF @InicieTransaccion=1 BEGIN
COMMIT
END
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
IF @InicieTransaccion=1 BEGIN
ROLLBACK
END
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Uncomitted
-- Otros detalles de los parametros
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[spUncommit] @Email nvarchar(50) AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @IdUsuario BIGINT
DECLARE @InicieTransaccion BIT
SELECT @IdUsuario=(SELECT IdUsuario FROM Usuarios WHERE Email=@Email)
IF (@IdUsuario IS NOT NULL)
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
BEGIN TRANSACTION
BEGIN TRY
SET @CustomError = 2001
SELECT * FROM Usuarios WHERE idUsuario=@idUsuario
COMMIT
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
ROLLBACK
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Repeatable
-- Email del usuario que para ver
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[spRepeatable] AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION
BEGIN TRY
SET @CustomError = 2001
SELECT * FROM Usuarios;
WAITFOR DELAY '00:00:10.000';
COMMIT
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
ROLLBACK
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Serializable
-- Email del usuario que para ver
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[spSerializable] AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @CustomError INT
DECLARE @Message VARCHAR(200)
DECLARE @IdUsuario BIGINT
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
BEGIN TRY
SET @CustomError = 2001
SELECT * FROM Usuarios
WAITFOR DELAY '00:00:10.000';
COMMIT
END TRY
BEGIN CATCH
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @Message = ERROR_MESSAGE()
ROLLBACK
RAISERROR('%s - Error Number: %i',
@ErrorSeverity, @ErrorState, @Message, @CustomError)
END CATCH
END
RETURN 0
GO
-----------------------------------------------------------
-- Autor: Owner
-- Fecha: 10/27/2014
-- Descripcion: Cursor que apunta a usuarios
-- Email del usuario que para ver
-----------------------------------------------------------
CREATE PROCEDURE [dbo].[deadCursor] AS BEGIN
DECLARE @InicieTransaccion BIT
SET @InicieTransaccion = 0
IF @@TRANCOUNT=0 BEGIN
SET @InicieTransaccion = 1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN TRANSACTION
END
BEGIN TRY
DECLARE _cursor CURSOR FOR
SELECT Email,Nombre,Apellido1 FROM Usuarios
ORDER BY Email;
OPEN _cursor
FETCH NEXT FROM _cursor
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Usuarios SET Apellido2 = 'Apellido'
WHERE CURRENT OF _cursor;
FETCH NEXT FROM _cursor
WAITFOR DELAY '00:00:01.000';
END
CLOSE _cursor;
DEALLOCATE _cursor;
COMMIT
END TRY
BEGIN CATCH
IF @InicieTransaccion=1 BEGIN
ROLLBACK
END
END CATCH
END
RETURN 0
GO
exec dbo.deadCursor
go
exec dbo.cambiarNombre'[email protected]','Superman'
exec dbo.cambiarNombre '[email protected]','Pedro'
go
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
exec dbo.[cambiarApellido] '[email protected]','Blak'
exec dbo.[spUncommit] '[email protected]'
go
exec dbo.[cambiarApellido] '[email protected]','Warner'
exec dbo.[spCommit] '[email protected]'
go
exec dbo.spRepeatable
exec dbo.cambiarNombre '[email protected]','Luis'
exec dbo.ingresarUsuario 'Pepe','Mark','Blade','1980-05-05','pepe','[email protected]','Espanol'
go
exec dbo.spSerializable
exec dbo.cambiarNombre '[email protected]','Carlos'
exec dbo.ingresarUsuario 'Luis','Carlos','valverde','1987-07-05','luis','[email protected]','Espanol'
go
go