-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.txt
137 lines (97 loc) · 2.66 KB
/
mysql.txt
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
start transaction;
select @m := max(RegionID) from Region where 1;
set @m = @m +1;
insert into Region (RegionID,RegionDescription) values (@m,'dheeraj');
commit;
_______________________________________________________________________________________
DELIMITER $$
CREATE PROCEDURE `sp_fail`()
BEGIN
DECLARE `_rollback` BOOL DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1;
START TRANSACTION;
insert into Region (RegionID,RegionDescription,One) values (10,'dheeraj',90);
IF `_rollback` THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END$$
DELIMITER ;
------------------------------------------------------------------------------------------
DELIMITER $$
CREATE FUNCTION test(region int) RETURNS int
DETERMINISTIC
BEGIN
DECLARE lvl integer;
SET lvl = region*region;
RETURN (lvl);
END $$
DELIMITER
__________________________________________________________________________________________
DELIMITER //
CREATE PROCEDURE GetAll(IN pn VARCHAR(255))
BEGIN
SELECT *
FROM Region
WHERE ProductName = pn;
END //
DELIMITER ;
-------------------------------------------------------------------------------------------
DELIMITER $$
CREATE PROCEDURE dheeraj(
IN one int,
OUT total INT)
BEGIN
SELECT count(ProductID)
INTO total
FROM Products
WHERE SupplierID = one;
END$$
DELIMITER ;
--------------------------------------------------------------------------------------------
CALL dheeraj(1,@total);
SELECT @total;
_____________________________________________________________________________________________
set @rollback = 0;
strat TRANSACTION;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @rollback = 1;
INSERT INTO `tablea` (`date`) VALUES (NOW());
INSERT INTO `tableb` (`date`) VALUES (NOW());
INSERT INTO `tablec` (`date`) VALUES (NOW());
IF @rollback THEN
ROLLBACK;
ELSE
select * from Products where 1;
COMMIT;
END IF;
---------------------------------------------------------------------------------------------
trigger
______________________________________________________________________________________________
DELIMITER $$
CREATE TRIGGER dheeraj
BEFORE insert ON client
FOR EACH ROW BEGIN
INSERT INTO test
SET name = 1,
age = 1;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER dheeraj1
BEFORE update ON client
FOR EACH ROW BEGIN
INSERT INTO test
SET name = old.money,
age = new.client_number;
END$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER dheeraj1
BEFORE delete ON client
FOR EACH ROW BEGIN
INSERT INTO test
SET name = old.money,
age = new.client_number;
END$$
DELIMITER ;