Quote:
The user will select multiple items as they are using multiple business applications.
Then that information should
not be stored in the employee table.
You will need three tables:
- The table which stores the list of employees;
- The table which stores the list of business applications;
- The table which stores the business applications which each employee uses;
CREATE TABLE [dbo].[tbl_EmployeeAdd](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Surname] [nvarchar](50) NULL,
[Department] [nvarchar](50) NULL,
[EmploymentType] [nvarchar](50) NULL,
[CommenceDate] [date] NULL,
[JobTitle] [nvarchar](50) NULL,
[TelephoneExt] [nchar](10) NULL,
[Gender] [nvarchar](10) NULL,
[Authorisedby] [nvarchar](50) NULL,
CONSTRAINT [PK_tbl_EmployeeAdd] PRIMARY KEY ([EmployeeID])
);
CREATE TABLE [dbo].[tbl_BusinessApplications](
[BusinessApplicationID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](20) NOT NULL,
CONSTRAINT [PK_tbl_BusinessApplications] PRIMARY KEY ([BusinessApplicationID])
);
CREATE TABLE [dbo].[tbl_Employee_BusinessApplications](
[EmployeeID] [int] NOT NULL,
[BusinessApplicationID] [int] NOT NULL,
CONSTRAINT [PK_tbl_Employee_BusinessApplications] PRIMARY KEY ([EmployeeID], [BusinessApplicationID]),
CONSTRAINT [FK_tbl_Employee_BusinessApplications_Employee) FOREIGN KEY ([EmployeeID]) REFERENCES [dbo].[tbl_EmployeeAdd] ([EmployeeID]) ON DELETE CASCADE,
CONSTRAINT [FK_tbl_Employee_BusinessApplications_Application) FOREIGN KEY ([BusinessApplicationID]) REFERENCES [dbo].[tbl_BusinessApplications] ([BusinessApplicationID]) ON DELETE CASCADE
);
You will need to pass the IDs of the selected business applications to your stored procedure. There are several ways to do that - for example, using Table Valued Parameters:
Use Table-Valued Parameters (Database Engine) - SQL Server | Microsoft Docs[
^]
Table-Valued Parameters - ADO.NET | Microsoft Docs[
^]
Using Table-Valued Parameters in SQL Server and .NET[
^]
CREATE TYPE [dbo].[IntegerList] As TABLE ([Value] int NOT NULL);
CREATE PROC [dbo].[EmployeeAdd]
(
@Name nvarchar(50),
@Surname nvarchar(50),
@Department nvarchar(50),
@EmploymentType nvarchar(50),
@CommenceDate date,
@JobTitle nvarchar(50),
@TelephoneExt nchar(10),
@Gender nvarchar(10),
@Authorisedby nvarchar(50),
@BusinessApplications [dbo].[IntegerList] READONLY
)
As
BEGIN
DECLARE @EmployeeID int;
SET NOCOUNT ON;
INSERT INTO dbo.tbl_EmployeeAdd
(
Name,
Surname,
Department,
EmploymentType,
CommenceDate,
JobTitle,
TelephoneExt,
Gender,
Authorisedby
)
VALUES
(
@Name,
@Surname,
@Department,
@EmploymentType,
@CommenceDate,
@JobTitle,
@TelephoneExt,
@Gender,
@Authorisedby
);
SET @EmployeeID = Scope_Identity();
INSERT INTO dbo.tbl_Employee_BusinessApplications
(
EmployeeID,
BusinessApplicationID
)
SELECT
@EmployeeID,
A.BusinessApplicationID
FROM
@BusinessApplications As L
INNER JOIN dbo.tbl_BusinessApplications As A
ON A.BusinessApplicationID = L.Value
;
END
GO
NB: Based on the names, I suspect you'll need to do something similar for
Workstations
,
FolderAccessRights
, and
EmailGroupAccess
as well.