Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi,

I am designing a database and I got a problem. In a large organization I am adding a number of employees, some new people will join the organization next year, and some will leave.
I want to generate employees per year. What and where should I add year data. If adding year with every employee, the database size will exceed extra, but this information is required for annual employee calculation.
Can anybody suggest anything?

Maaham

Moved from OP's answer:
I need % age employees per year and data of employee per year on a specific date.

Moved from OP's answer(round 2):
currently employees and still working is also a project, yet i am working on funds distributed to retired employees, as normally we see example of pension.
your above both answers are much helpful
i want to generate the foll result for example:

no of pensioners in year 2007= 50
no of pensioners in year 2008= 58
no of pensioners in year 2009= 47

and 50 record sets for 2007 having individual correct information and so on.
Posted
Updated 25-Jan-11 8:13am
v3
Comments
Indivara 25-Jan-11 1:12am    
Date employed and date resigned as two columns in the table? How else would you do it? What exactly is the problem with the size?
Sergey Alexandrovich Kryukov 25-Jan-11 1:16am    
The real question is: do you need employee information per individual employee for any other reason? Or you're trying to avoid a table of employees at all?
Sergey Alexandrovich Kryukov 25-Jan-11 1:25am    
You did not answer my question. You answer is not clear.
Please, don't post anything related to your question as Answer: nobody will be notified, you fake answer will be removed.

OP posted:
"i need % age employees per year and data of employee per year, on a specific date"
Sandeep Mewara 25-Jan-11 2:41am    
OP posted:
yes i need employee information per individual information, like pay will be revised annually, so that why individual main information is also needed
Sergey Alexandrovich Kryukov 25-Jan-11 13:55pm    
It means the employee table is needed anyway, which make the solution obvious.

You'll find a practical "real world" answer to your question, and much more, by downloading this script for SQL Server 2008 - It's still under development, and will at some time hopefully form the basis for a series of articles.
Blitz Data Model[^]

A person is a specialization of a Party.

As a person, a party may have an employee role, for a period of time, with an other party in the role as an employeer.

There is currently more than 800 tables in this model, and while I've planned a number of changes, the model shows a practical solution to your problem.

The model uses bigint for date and time - values should be stored in "UTC Ticks" (See .Net DateTime.Ticks for an explanation). Tests has shown that this speeds up operations, and it enables some operations at the database level that's pretty hard to execute efficiently using the built in types.

Regards
Espen Harlinn
 
Share this answer
 
As Indivara indicated use two columns on for date employed and one for date terminated.
When you query for employees for a given year check these two columns to be sure the year is within.
You do not need to make a column per year the person is employed.
 
Share this answer
 
As metioned, this can easily be achieved by adding a few columns.

If you want historical information, you might consider something along the following lines.

Information about an Employee
SQL
CREATE TABLE [Employee] (
    [EmployeeID] [int] NOT NULL ,
    [Initial] [varchar] (10) ,
    [Forename] [varchar] (50),
    [Surname] [varchar] (50) ,
    [PreferredName] [varchar] (50) ,
    [DOB] [smalldatetime] NOT NULL ,
    [DateJoinedCompany] [smalldatetime] NULL ,
    [ContinuousServiceDate] [smalldatetime] NULL ,
    [LeaveDate] [smalldatetime] NULL ,
    CONSTRAINT [PK_Employees] PRIMARY KEY  CLUSTERED
    (
        [EmployeeID]
    )  ON [PRIMARY]
) ON [PRIMARY]
GO


Information about employment history.

This could hold information such as hours contracted, date started job + anything else you might need here.

SQL
CREATE TABLE [JobDetails] (
    [EmployeeID] [int] NOT NULL ,
    [ContractedHours] [decimal](5, 2) NULL ,
    [JobCategoryID] [smallint] NULL ,
    [JobDate] [smalldatetime] NULL,
    CONSTRAINT [FK_JobDetails_Employee] FOREIGN KEY
    (
        [EmployeeID]
    ) REFERENCES [Employee] (
        [EmployeeID]
    )
) ON [PRIMARY]


Information about pay.

Every time the employees rate of pay changes, you'd have a record here
SQL
CREATE TABLE [EmployeePayRates] (
    [EmployeeID] [int] NOT NULL ,
    [PayDate] [datetime] NOT NULL ,
    [PayRate] [money] NULL,
    CONSTRAINT [FK_EmployeePayRates_Employee] FOREIGN KEY
    (
      [EmployeeID]
    ) REFERENCES [Employee] (
      [EmployeeID]
    )
) ON [PRIMARY]


So for example, if an employee is promoted you wouldn't change the Employee table - you just add records to JobDetails (new job) and EmployeePayRates (new rate of pay)

I'd recommend keeping JobDetails and EmployeePayRates in different tables, since an employee could still be within their current role but may get a pay rise.
 
Share this answer
 
v3
Just have 3 new coloumns. DateCreated,DateModified,Active.
DateCreated- will tell you the date the employee is hired.
Active = will tell you if he is still working
DateModified - will tell you when he left
 
Share this answer
 
ok, apart from that critical solution, i am interested to do DBA, how should i start doing course, i am unable to trace the roadmap.
i want to prepare for the test of OCP.
can anybody guide me ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900