EMPLOYEE_INFORMATION
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EMPLOYEE_INFORMATION](
[ID] [uniqueidentifier] NULL,
[USERNAME] [nvarchar](50) NULL,
[ADDRESS] [nvarchar](50) NULL,
[DOB] [date] NULL,
[POSITION] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SALARY
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SALARY](
[POSITION] [nvarchar](50) NULL,
[SALARY] [int] NULL
) ON [PRIMARY]
GO
USER_LOGIN
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[USER_LOGIN](
[USER_ID] [uniqueidentifier] NULL,
[USERNAME] [nvarchar](50) NULL,
[EMAIL] [nvarchar](50) NULL,
[PASSWORD] [nvarchar](50) NULL
) ON [PRIMARY]
GO
Insert data EMP & USER_LOGIN Table
DECLARE @ID UNIQUEIDENTIFIER
SET @ID = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID, 'Chanui', 'Kyonggi', '1999-05-05', 'CEO')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID, 'Chanui', 'hcu55@naver.com', 'chanui55')
DECLARE @ID2 UNIQUEIDENTIFIER
SET @ID2 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID2, 'Joonui', 'Seoul', '2000-12-28', 'Vice Chairman')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID2, 'Joonui', 'hju1228@naver.com', '123456')
DECLARE @ID3 UNIQUEIDENTIFIER
SET @ID3 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID3, 'Famous', 'Kyonggi', '1999-06-04', 'General Manager')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID3, 'Famous', 'famous@naver.com', '11111')
DECLARE @ID4 UNIQUEIDENTIFIER
SET @ID4 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID4, 'ham', 'Seoul', '1999-03-23', 'General Manager')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID4, 'ham', 'hhj@naver.com', '00000')
DECLARE @ID5 UNIQUEIDENTIFIER
SET @ID5 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID5, 'Sunwoo', 'Kyonggi', '1998-12-04', 'Staff')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID5, 'Sunwoo', 'psw1204@nvaer.com', 'psw123')
DECLARE @ID6 UNIQUEIDENTIFIER
SET @ID6 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID6, 'Sujin', 'Seoul', '1997-02-15', 'Staff')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID6, 'Sujin', 'suji71@naver.com', 'qwer1234')
DECLARE @ID7 UNIQUEIDENTIFIER
SET @ID7 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID7, 'Wonbin', 'Seoul', '2000-04-21', 'Manager')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID7, 'Wonbin', 'wonbin@naver.com', 'wonbin123')
DECLARE @ID8 UNIQUEIDENTIFIER
SET @ID8 = NEWID();
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@ID8, 'Jeonghyo', 'Kyonggi', '2001-09-15', 'Intern')
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@ID8, 'Jeonghyo', 'jjang@naver.com', '12345')
CREATE VIEW [dbo].[COMBINE_TABLE] AS
SELECT e.ID, e.USERNAME, u.EMAIL, u.[PASSWORD], e.ADDRESS, e.DOB, e.[POSITION], s.SALARY
FROM EMPLOYEE_INFORMATION AS e
JOIN SALARY AS s ON e.[POSITION] = s.[POSITION]
JOIN USER_LOGIN AS u ON e.USERNAME = u.USERNAME
PROC_EMP
CREATE PROCEDURE [dbo].[PROC_EMP](
@EMP_NAME NVARCHAR(50),
@EMP_ADDRESS NVARCHAR(50),
@EMP_DOB DATE,
@EMP_POSITION NVARCHAR(50),
@EMP_UID UNIQUEIDENTIFIER OUTPUT
) AS
BEGIN
INSERT INTO EMPLOYEE_INFORMATION(ID, USERNAME, ADDRESS, DOB, [POSITION])
VALUES(@EMP_UID, @EMP_NAME, @EMP_ADDRESS, @EMP_DOB, @EMP_POSITION);
SELECT @EMP_UID, @EMP_NAME, @EMP_ADDRESS, @EMP_DOB, @EMP_POSITION;
END
PROC_SALARY
CREATE PROCEDURE [dbo].[PROC_SALARY](
@SAL_POSITION NVARCHAR(50),
@SAL_SALARY INT
) AS
BEGIN
INSERT INTO SALARY([POSITION],SALARY)
VALUES(@SAL_POSITION, @SAL_SALARY);
SELECT @SAL_POSITION, @SAL_SALARY;
END
PROC_USER_LOGIN
CREATE PROCEDURE [dbo].[PROC_USER_LOGIN](
@LOGIN_UID UNIQUEIDENTIFIER OUTPUT,
@LOGIN_NAME NVARCHAR(50),
@LOGIN_EMAIL NVARCHAR(50),
@LOGIN_PASSWORD NVARCHAR(50)
) AS
BEGIN
INSERT INTO USER_LOGIN(USER_ID, USERNAME, EMAIL, [PASSWORD])
VALUES(@LOGIN_UID, @LOGIN_NAME, @LOGIN_EMAIL, @LOGIN_PASSWORD);
SELECT @LOGIN_UID, @LOGIN_NAME, @LOGIN_EMAIL, @LOGIN_PASSWORD;
END
EXEC Table
DECLARE @ID UNIQUEIDENTIFIER
SET @ID = NEWID();
EXEC PROC_EMP 'Sungwan', 'Seoul', '1999-03-29', 'Intern', @ID;
EXEC PROC_USER_LOGIN @ID, 'Sungwan', 'hongsung@gmail.com', 'sungwan123';
SELECT e.ID, e.USERNAME, u.EMAIL, u.[PASSWORD], e.ADDRESS, e.DOB, e.[POSITION], s.SALARY
FROM EMPLOYEE_INFORMATION AS e
JOIN SALARY AS s ON e.[POSITION] = s.[POSITION]
JOIN USER_LOGIN AS u ON e.ID = u.USER_ID