Documentos de Académico
Documentos de Profesional
Documentos de Cultura
TrnsacSql PDF
TrnsacSql PDF
!
! "
#
$ ! "
! %
& ' ! ! # (
! ! % )
#
(( ) !
!
! *$+ ,$ ! ! "
$ ! !
# &-' $
! $ . !
$ " / # !
0 1$,$2
3 %! # $ $+
$ ! %! # $ $+
! 4 $ $+ #
!
5 ! ! ) "
$ # $ $+
! !/ .
$ . ! ! ! "
/ .
6
4 7 $ $+ ! ! %" #
$ ! 3 .
$ 2
# $ $+ %!
! 7 *
. !
$. 2 ! 2
+ +
6 , 8
9
: ; " 6<=
. !!
2
$ $ $+ 2 ; " 6<=
3 !
> $ $+ )
! " / .
$ $+
3 . 2 . ! !
" #$ ! "
+ .
). * 2
Para más información consultar: Libros en Pantalla – Búsqueda - Lenguaje de control de flujo
En cuanto a funciones ver: Libros en Pantalla – Búsqueda - Funciones (T-SQL)
)
' & ' % & ' #
! 7
7 #
$ ) .
3 . . ) '
$ $+ ) !
8> . "
% ! ! A,>; A>;
% !/ ! ! 2
9 # !
!. % . $ .
$ $+ . 2
5 ! % !/ ! !.
. %! 5
%!
5 # ) '
7 "
" . ! $D$+4 , & ) AE'
! ) ' /
$
! $D$+4 , & AE'
* ) !
$ F )
% & . ) ' '
7 ! .
$ & ' "
)
4 . . ) .
& ' " %
% "
. $ # # % G!
H
6.5. Transacciones
" # ! 5 !
!
#3
!. ! #
) ! 4 # !
! % +>; ; @
, 5 + @>5 % !
,> ? +I , 5 + @>5
BEGIN TRAN
INSERT prestamos VALUES( , , etc.)
UPDATE ejemplares SET disponible = 0 where signatura = etc.
COMMIT TRAN
GO
) 2
• +
*
)
) %
) L
% 4 ) )
% ?$8@5 , 5
• +
?$8@5 , 5 " +>; ; @ , 5
,> ? +I , 5
• %
+>; ; @ ,> ? +I $ $
@; 3 @+@ M , 5 + @>5 >5
7 ) "
) % +>; ; @ , 5 >! %
,>> ? +I
%! ) $ $+ 3
%! %! )
&@5 $, 43* $" *$ $ $'
E
4 #
' &'
) "
)
" /
J / . 2
begin transaction
insert c values ('X')
insert b values ('X') –- falla la referencia
commit transaction
go
# %
. L ) %
% ! " )
) 3 ) .
) & . ' . 7
) . +>; ; @ )
$ % % %
! ! ( ( $,,>, # $
N + M ?>,
; /
& ( ( $,,>, ) % 7 '2
begin transaction
insert c values ('X')
if (@@error <> 0) goto Hay_error
insert b values ('X') –- falla la referencia
if (@@error <> 0) goto Hay_error
commit transaction
Hay_error:
rollback transaction
go
select * from c -- ¡No devuelve 'X'!, ya que no se confirma
O
> )
$ N + M ?>, / )
& ! ( ( $,,>, PQ / '
$ / ) ' &' 2
set xact_abort on
begin transaction
insert c values ('X')
insert b values ('X') –- falla la referencia
commit transaction
go
N + M ?>,
3 . %"
.
% .
. %
" %/ .
) . !/
"
1 " ) &
' " ) &
'
+,$ $
3,>+$*4,$ 4 2
RETURN n
+ # >4 34
) ) #
<
% #) # .
/
# >4 34 #
)
% # )
# ).
# % ) # .
$5+,R3 @>5 ) ! !
+,$ $ 3,>+$*4,$ $ $5+,R3 @>5
!
4 # % /
. !
. $ ! #
$N$+4 $ $ 2
[[EXEC[UTE]]
[@valor_de_retorno=] NombreProcedimiento
[[@parámetro =] {valor | @variable [OUTPUT] |
[DEFAULT]] [,…n]
J % . " .
3 >! *
! " ! 2
$ . 2
ObtenerTitulosDeAutor 'Cervantes'
o
EXEC ObtenerTitulosDeAutor 'Cervantes'
o
EXEC ObtenerTitulosDeAutor @autor='Cervantes'
S
3 ) ! " )
! ! !/ ) & ) '
! ! ( ( ,>0 +>45 & 7 ) ) 7
' $ !
! !
! L
%! # ! !
* % % !!
) %! 5 ! % % / !
/ ! @ ! % % !
! )
$ ) ! ! !
@CuentaLib " @CuentaSoc ) ! "
>! # !
(Total_Libros y Total_Socios)
" , # ! !
" 7 . " /
! / ! "
! ! ) $ !
! / " ! %!
) / &
'
6.7. DESENCADENADORES (TRIGGERS)
. ) ! 4
) !
@5 $, 43* $ *$ $ $
4 2
$ 7 "
+ 2
• &+,$
$'
• !. &*,>3'
• ) !. & $,'
• 3 &8, 5 " ,$J>I$'
! 2
− ! ) % F .
@5 $, 43* $ ! !
− ! )
*$ $ $ 43* $ ! !
# 4 43* $ 2
) ! " )
! " !
J . 2$ %
!
$ # 7 ) /
) $ %3 ! . !
5 )3 -T69:HT 3 !
2
/ >5 *$ $ $ + + *$
! ) "
! & ! ) !
) " .!
" ' #
! ) & @5 $, ! !
% ) ' ! & *$ $ $
! % ) '
J / . ! !
! 3 " 3 & 3 9 9" 3 9
' ! ! ) )
A>,$@85 I$R ) !
!
" )
$ 2
Use precios
go
go
, ' - ) )
' , % - % . * /0-.1 2
* ) *+ *
66
' ! !
' ! ! #
INSERT INTO Prec2 VALUES ('9999','55',12.50)
" , # ! # /
! / ! " !