/*
USE library
BEGIN TRANSACTION

	SET IDENTITY_INSERT member ON
	INSERT member (member_no, lastname, firstname, middleinitial)
	VALUES (16101, 'Walters', 'B.', 'L')
	SET IDENTITY_INSERT member OFF

	INSERT juvenile
	VALUES (16101, 1, DATEADD(YY, -18, DATEADD(DD, -1, GETDATE()))) -- минус один день и 18 лет от сегодняшней даты

COMMIT TRANSACTION;
*/

/*
SELECT juvenile.member_no, street, city, state, zip, phone_no, DATEADD(YY, 1, GETDATE())
FROM library.dbo.juvenile
JOIN library.dbo.adult
ON juvenile.adult_member_no = adult.member_no
WHERE birth_date <= DATEADD(YY, -18, GETDATE())
ORDER BY member_no; 
*/

/*
INSERT INTO library.dbo.adult
SELECT juvenile.member_no, street, city, state, zip, phone_no, DATEADD(YY, 1, GETDATE())
FROM library.dbo.juvenile
JOIN library.dbo.adult
ON juvenile.adult_member_no = adult.member_no
WHERE birth_date <= DATEADD(YY, -18, GETDATE())
ORDER BY member_no; 

SELECT * FROM library.dbo.adult WHERE member_no = 16101;
*/

/*
SELECT juvenile.member_no, adult.member_no
FROM library.dbo.juvenile
JOIN library.dbo.adult
ON juvenile.member_no = adult.member_no;
*/

/*
DELETE FROM library.dbo.juvenile
WHERE juvenile.member_no IN
(
SELECT juvenile.member_no, adult.member_no
FROM library.dbo.juvenile
JOIN library.dbo.adult
ON juvenile.member_no = adult.member_no
);
*/


/*
SELECT * FROM library.dbo.juvenile WHERE member_no = 16101;
*/