-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.sql
202 lines (151 loc) · 5.88 KB
/
testing.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
/*
SQLyog Community v13.1.7 (64 bit)
MySQL - 10.4.20-MariaDB : Database - testing
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`testing` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `testing`;
/*Table structure for table `mstr_father` */
DROP TABLE IF EXISTS `mstr_father`;
CREATE TABLE `mstr_father` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`age` varchar(20) DEFAULT NULL,
`dob` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
/*Data for the table `mstr_father` */
insert into `mstr_father`(`id`,`user_id`,`name`,`age`,`dob`) values
(1,1,'Prasad','23 years','1985-02-01'),
(3,4,'nagesh','23 years','1985-02-01'),
(4,2,'sangram','50 years','1912-02-01'),
(5,5,'Nitesh','50 years','1912-02-01');
/*Table structure for table `mstr_mother` */
DROP TABLE IF EXISTS `mstr_mother`;
CREATE TABLE `mstr_mother` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`age` varchar(20) DEFAULT NULL,
`dob` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
/*Data for the table `mstr_mother` */
insert into `mstr_mother`(`id`,`user_id`,`name`,`age`,`dob`) values
(1,5,'sangita','50 years','1912-02-01'),
(2,1,'pratiksha','40 years','1945-02-05'),
(3,2,'namrata','30 years','1999-03-15'),
(4,3,'harshada','30 years','1999-03-15');
/*Table structure for table `mstr_user` */
DROP TABLE IF EXISTS `mstr_user`;
CREATE TABLE `mstr_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`address` varchar(100) NOT NULL,
`dob` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
/*Data for the table `mstr_user` */
insert into `mstr_user`(`id`,`name`,`address`,`dob`) values
(1,'aa','aaa','2020-02-01'),
(2,'Siya','Mumbai','1998-10-02'),
(3,'Siya','Mumbai','1998-10-02'),
(4,'Prabhas','Mumbai','1998-10-02'),
(5,'Pratik','Mumbai','1998-10-02');
/* Procedure structure for procedure `pro_add_father` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_add_father` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_add_father`(in `_user_id` int,in `_name` varchar(50),in `_age` varchar(50),in `_dob` date)
NO SQL
BEGIN
set @usercont:=(select count(user_id) from mstr_father where user_id=_user_id);
if @usercont=0 then
insert into mstr_father(user_id,name,age,dob) values(_user_id,_name,_age,_dob);
select 1 as result;
else
UPDATE mstr_father SET NAME=_name,age=_age,dob=_dob WHERE user_id=_user_id;
select 2 as result;
end if;
END */$$
DELIMITER ;
/* Procedure structure for procedure `pro_add_mother` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_add_mother` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_add_mother`(in `_user_id` int,in `_name`varchar(50),in `_age` varchar(50),in `_dob` date)
NO SQL
BEGIN
set @usercont:=(select count(user_id)from mstr_mother where user_id=_user_id);
if @usercont=0 then
INSERT INTO mstr_mother(user_id,NAME,age,dob) VALUES(_user_id,_name,_age,_dob);
SELECT 1 AS result;
else
UPDATE mstr_mother SET NAME=_name,age=_age,dob=_dob WHERE user_id=_user_id;
SELECT 2 AS result;
end if;
END */$$
DELIMITER ;
/* Procedure structure for procedure `pro_family_list` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_family_list` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_family_list`()
NO SQL
BEGIN
SELECT users.name,users.address,users.dob,father.name AS father_name,father.age AS father_age,father.dob AS father_dob,mother.name AS mother_name,mother.age AS mother_age,mother.dob AS mother_dob
FROM mstr_user users
INNER JOIN mstr_father father ON users.id=father.user_id
INNER JOIN mstr_mother mother ON users.id=mother.user_id;
select * from mstr_user;
END */$$
DELIMITER ;
/* Procedure structure for procedure `pro_list_show` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_list_show` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_list_show`()
BEGIN
select * from mstr_user;
end */$$
DELIMITER ;
/* Procedure structure for procedure `pro_update_user` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_update_user` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_update_user`(in `_user_id` int,in `_name` varchar(50),in `_age` varchar(20),in `_dob` date)
NO SQL
BEGIN
update mstr_father set name=_name,age=_age,dob=_dob where user_id=_user_id;
select 1 as result;
END */$$
DELIMITER ;
/* Procedure structure for procedure `pro_user_list` */
/*!50003 DROP PROCEDURE IF EXISTS `pro_user_list` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_user_list`(in `_dob` date)
NO SQL
BEGIN
if _dob="2020-02-01" then
select * from mstr_user where dob=_dob;
else
SELECT * FROM testingnew.mstr_user WHERE dob=_dob;
end if;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sproc_adduser` */
/*!50003 DROP PROCEDURE IF EXISTS `sproc_adduser` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_adduser`(in `_name` varchar(50),in `_address` varchar(100),in `_dob` date)
NO SQL
BEGIN
insert into mstr_user(name,address,dob) values(_name,_address,_dob);
select 1 as result;
END */$$
DELIMITER ;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;