The script also creates records in each table that are consistent with the following demonstration:
Understanding Relational Division in SQL
USE [JobSkills] GO /****** Object: Table [dbo].[Applicant] Script Date: 11/12/2018 9:10:48 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Applicant]( [applicantID] [int] NOT NULL, [lastName] [varchar](50) NOT NULL, CONSTRAINT [PK_Applicant] PRIMARY KEY CLUSTERED ( [applicantID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ApplicantSkill] Script Date: 11/12/2018 9:10:49 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ApplicantSkill]( [employeeSkillID] [int] NOT NULL, [applicantID] [int] NOT NULL, [skillID] [int] NOT NULL, CONSTRAINT [PK_ApplicantSkill] PRIMARY KEY CLUSTERED ( [employeeSkillID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[Job] Script Date: 11/12/2018 9:10:49 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Job]( [jobID] [int] NOT NULL, [jobName] [varchar](50) NOT NULL, CONSTRAINT [PK_Job] PRIMARY KEY CLUSTERED ( [jobID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[JobSkill] Script Date: 11/12/2018 9:10:49 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[JobSkill]( [jobSkillID] [int] NOT NULL, [jobID] [int] NOT NULL, [skillID] [int] NOT NULL, CONSTRAINT [PK_JobSkill] PRIMARY KEY CLUSTERED ( [jobSkillID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[Skill] Script Date: 11/12/2018 9:10:49 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Skill]( [skillID] [int] NOT NULL, [skillName] [varchar](50) NOT NULL, CONSTRAINT [PK_Skill] PRIMARY KEY CLUSTERED ( [skillID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO INSERT [dbo].[Applicant] ([applicantID], [lastName]) VALUES (100, N'Kline') GO INSERT [dbo].[Applicant] ([applicantID], [lastName]) VALUES (101, N'Smith') GO INSERT [dbo].[Applicant] ([applicantID], [lastName]) VALUES (102, N'Jones') GO INSERT [dbo].[Applicant] ([applicantID], [lastName]) VALUES (103, N'Brown') GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1000, 100, 1) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1001, 100, 2) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1002, 101, 3) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1003, 102, 1) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1004, 102, 4) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1005, 103, 1) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1006, 103, 4) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1007, 103, 3) GO INSERT [dbo].[ApplicantSkill] ([employeeSkillID], [applicantID], [skillID]) VALUES (1008, 103, 2) GO INSERT [dbo].[Job] ([jobID], [jobName]) VALUES (10, N'Software Developer') GO INSERT [dbo].[Job] ([jobID], [jobName]) VALUES (11, N'Business Analyst') GO INSERT [dbo].[Job] ([jobID], [jobName]) VALUES (12, N'Data Analyst') GO INSERT [dbo].[JobSkill] ([jobSkillID], [jobID], [skillID]) VALUES (100, 10, 1) GO INSERT [dbo].[JobSkill] ([jobSkillID], [jobID], [skillID]) VALUES (101, 10, 4) GO INSERT [dbo].[JobSkill] ([jobSkillID], [jobID], [skillID]) VALUES (102, 11, 2) GO INSERT [dbo].[JobSkill] ([jobSkillID], [jobID], [skillID]) VALUES (103, 11, 3) GO INSERT [dbo].[Skill] ([skillID], [skillName]) VALUES (1, N'SQL') GO INSERT [dbo].[Skill] ([skillID], [skillName]) VALUES (2, N'Public Speaking') GO INSERT [dbo].[Skill] ([skillID], [skillName]) VALUES (3, N'Project Management') GO INSERT [dbo].[Skill] ([skillID], [skillName]) VALUES (4, N'Javascript') GO ALTER TABLE [dbo].[ApplicantSkill] WITH CHECK ADD CONSTRAINT [FK_ApplicantSkill_Applicant] FOREIGN KEY([applicantID]) REFERENCES [dbo].[Applicant] ([applicantID]) GO ALTER TABLE [dbo].[ApplicantSkill] CHECK CONSTRAINT [FK_ApplicantSkill_Applicant] GO ALTER TABLE [dbo].[ApplicantSkill] WITH CHECK ADD CONSTRAINT [FK_ApplicantSkill_Skill] FOREIGN KEY([skillID]) REFERENCES [dbo].[Skill] ([skillID]) GO ALTER TABLE [dbo].[ApplicantSkill] CHECK CONSTRAINT [FK_ApplicantSkill_Skill] GO ALTER TABLE [dbo].[JobSkill] WITH CHECK ADD CONSTRAINT [FK_JobSkill_Job] FOREIGN KEY([jobID]) REFERENCES [dbo].[Job] ([jobID]) GO ALTER TABLE [dbo].[JobSkill] CHECK CONSTRAINT [FK_JobSkill_Job] GO ALTER TABLE [dbo].[JobSkill] WITH CHECK ADD CONSTRAINT [FK_JobSkill_Skill] FOREIGN KEY([skillID]) REFERENCES [dbo].[Skill] ([skillID]) GO ALTER TABLE [dbo].[JobSkill] CHECK CONSTRAINT [FK_JobSkill_Skill] GO
No comments:
Post a Comment