-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson8.sql
144 lines (97 loc) · 1.88 KB
/
Lesson8.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
USE PERSONEL;
-- trigger oluşturma
CREATE TRIGGER trg_TblPersonel_forInsert
ON PERSONELLER
FOR INSERT
AS BEGIN
SELECT * FROM inserted;
END
-- trigger silme
DROP TRIGGER trg_TblPersonel_forInsert;
-- ALTER MODİFİYE CEKME
ALTER TRIGGER trg_TblPersonel_forInsert
ON PERSONELLER
FOR INSERT
AS BEGIN
PRINT 'FDSFDS';
END
insert into PERSONELLER VALUES('hghgf', 'gfgf', 'gfg', 50);
-- tablodaki degisiklikleri takip etmek icin
CREATE TABLE TblPersonellerAudit(
id INT PRIMARY KEY IDENTITY(1,1),
AuditData NVARCHAR(100)
);
CREATE TRIGGER trg_TblPersonel_forInsert2
ON PERSONELLER
FOR INSERT
AS BEGIN
DECLARE @id INT;
SELECT @id = id from inserted;
INSERT INTO TblPersonellerAudit VALUES(CAST(@id AS NVARCHAR(3)) + 'id burada' + CAST(GETDATE() AS nvarchar(20)))
END
insert into PERSONELLER VALUES('hghgf', 'gfgf', 'gfg', 50);
SELECT * FROM TblPersonellerAudit;
-- delete trigger
CREATE TRIGGER trg_TblPersonel_forDelete
ON PERSONELLER
FOR DELETE
AS BEGIN
SELECT * FROM deleted;
END
-- TSQL
-- IF
DECLARE @sayi INT
SET @sayi = 5;
IF @sayi>1
BEGIN
PRINT 'BUYUKTUR'
END
DECLARE @count INT;
SET @count = 8;
IF @count=99
BEGIN
PRINT @count
END
ELSE IF @count=98
BEGIN
PRINT @count
END
ELSE
BEGIN
PRINT @count
END
-- WHILE
WHILE @sayi<=99
BEGIN
PRINT 'CALİSİYOR'
SET @sayi = @sayi+1
END
-- sistem fonksiyon degiskenleri
SELECT @@CPU_BUSY
-- case
SELECT [ad], [zamli maas] =
CASE [cinsiyet]
WHEN 'K' THEN maas*3
WHEN 'E' THEN maas*2
ELSE -99
END,
[id]
FROM Personeller;
-- case like
SELECT [name], [a ve m] =
CASE
WHEN [name] LIKE 'a%' THEN 'A'
WHEN [name] LIKE 'm%' THEN 'M'
ELSE 'No'
END,
[id]
FROM Personeller;
-- TRY CATCH
BEGIN TRY
DROP TABLE olmayanTablo
END TRY
BEGIN CATCH
PRINT 'HATA'
PRINT ERROR_NUMBER();
PRINT ERROR_MESSAGE();
END CATCH