forked from binhtranmcs/DBAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testAss2.sql
46 lines (39 loc) · 1.01 KB
/
testAss2.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
use Bookstore;
--INSERT INTO account (username, password, type_account, accid)
--VALUES ('admin', 'admin', 'Admin', 0)
--INSERT INTO customer (caddress, cname, cemail)
--VALUES ('123', 'Thanh', '[email protected]')
DROP FUNCTION IF EXISTS getMAX_IDCustomer
GO
CREATE FUNCTION getMAX_IDCustomer
(
)
RETURNS int
AS
BEGIN
DECLARE @ans int;
SELECT @ans = MAX(cid) FROM customer
RETURN @ans
END;
GO
DROP FUNCTION IF EXISTS getMAX_IDEmployee
GO
CREATE FUNCTION getMAX_IDEmployee
(
)
RETURNS int
AS
BEGIN
DECLARE @ans int;
SELECT @ans = MAX(eid) FROM employee
RETURN @ans
END;
GO
--INSERT INTO employee VALUES('bienhoa', 'thong', '[email protected]')
insert into employee(eaddress, ename, eemail)
VALUES('abc123', 'thanh', '[email protected]')
declare @retval int;
exec @retval = getMAX_IDEmployee;
insert INTO account (username, password, type_account, accid)
SELECT 'e2', '1234', 'Employee', MAX(eid) from employee
--insert into account ('employee2', '1234', 'Employee', accid in Select cid from customer order by cid desc limit 1)