AdventureWorks
HumanResources.EmployeeDepartmentHistory Table
Description
Employee department transfers.
Properties
Creation Date08/01/2010 08:40
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows296
Data Space Used16.00 KB
Index Space Used48.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key EmployeeIDEmployee identification number. Foreign key to Employee.EmployeeID.int4   
Primary Key DepartmentIDDepartment in which the employee worked including currently. Foreign key to Department.DepartmentID.smallint2   
Primary Key ShiftIDIdentifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID.tinyint1   
Primary Key StartDateDate the employee started work in the department.datetime4   
 EndDateDate the employee left the department. NULL = Current department.datetime4  
 ModifiedDateDate and time the record was last updated.datetime4 
(getdate())
 
Indexes
IndexDescriptionPrimaryUnique
IX_EmployeeDepartmentHistory_DepartmentIDNonclustered index.  
IX_EmployeeDepartmentHistory_ShiftIDNonclustered index.  
PK_EmployeeDepartmentHistory_EmployeeID_StartDate_DepartmentIDPrimary key (clustered) constraint
Check Constraints
NameDescriptionExpression
CK_EmployeeDepartmentHistory_EndDateCheck constraint [EndDate] >= [StartDate] OR [EndDate] IS NUL
([EndDate]>=[StartDate] OR [EndDate] IS NULL)
Relationships
RelationshipDescription
FK_EmployeeDepartmentHistory_Department_DepartmentIDForeign key constraint referencing Department.DepartmentID.
FK_EmployeeDepartmentHistory_Employee_EmployeeIDForeign key constraint referencing Employee.EmployeeID.
FK_EmployeeDepartmentHistory_Shift_ShiftIDForeign key constraint referencing Shift.ShiftID
Objects that depend on HumanResources.EmployeeDepartmentHistory
 Database ObjectObject TypeDescriptionDep Level
HumanResources.vEmployeeDepartment viewHumanResources.vEmployeeDepartmentViewReturns employee name, title, and current department.1
HumanResources.vEmployeeDepartmentHistory viewHumanResources.vEmployeeDepartmentHistoryViewReturns employee name and current and previous departments.1
Objects that HumanResources.EmployeeDepartmentHistory depends on
 Database ObjectObject TypeDescriptionDep Level
Person.Contact tablePerson.ContactTableNames of each employee, customer contact, and vendor contact.2
HumanResources.Department tableHumanResources.DepartmentTableLookup table containing the departments within the Adventure Works Cycles company.1
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.1
dbo.Flag datatypedbo.FlagUser Defined Data Type 2
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 3
dbo.Phone datatypedbo.PhoneUser Defined Data Type 3
HumanResources.Shift tableHumanResources.ShiftTableWork shift lookup table.1
SQL
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [HumanResources].[EmployeeDepartmentHistory](
	[EmployeeID] [int] NOT NULL,
	[DepartmentID] [smallint] NOT NULL,
	[ShiftID] [tinyint] NOT NULL,
	[StartDate] [datetime] NOT NULL,
	[EndDate] [datetime] NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_EmployeeDepartmentHistory_EmployeeID_StartDate_DepartmentID] PRIMARY KEY CLUSTERED 
(
	[EmployeeID] ASC,
	[StartDate] ASC,
	[DepartmentID] ASC,
	[ShiftID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [HumanResources].[EmployeeDepartmentHistory]  WITH CHECK ADD  CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID] FOREIGN KEY([DepartmentID])
REFERENCES [Department] ([DepartmentID])
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID]
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory]  WITH CHECK ADD  CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_EmployeeID] FOREIGN KEY([EmployeeID])
REFERENCES [Employee] ([EmployeeID])
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_EmployeeID]
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory]  WITH CHECK ADD  CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] FOREIGN KEY([ShiftID])
REFERENCES [Shift] ([ShiftID])
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID]
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory]  WITH CHECK ADD  CONSTRAINT [CK_EmployeeDepartmentHistory_EndDate] CHECK  (([EndDate]>=[StartDate] OR [EndDate] IS NULL))
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [CK_EmployeeDepartmentHistory_EndDate]
ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] ADD  CONSTRAINT [DF_EmployeeDepartmentHistory_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
See Also

Related Objects

HumanResources Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.