-2

Possible Duplicate:
create sql table programmatically

So for my project, I need to create a a roster table (which includes a list of employees and their hours for the week, Saturday to Friday). However, I have no idea how to add this specific table to the database. I am aware how to add specific fields from a textbox to my sql server database, but I just cannot save a table to a database! The idea is to add these weekly roster tables to the database. Any help will be greatly appreciated.

Community
  • 1
  • 1
  • 2
    Are you creating the table from scratch or just populating it? If you're creating a table from scratch you'll need to use the CREATE TABLE SQL Command. – Frazell Thomas Dec 20 '12 at 18:34
  • 4
    Asked and answered: http://stackoverflow.com/questions/10033758/create-sql-table-programmatically – Pete Dec 20 '12 at 18:34

1 Answers1

0

You probably don't want to add a new table to the database for each roster, once per week. That will make historical queries (for example, the number of hours an employee worked for the last four weeks) much more difficult than they need to be. A better approach might be to use a couple of tables you create up front:

Rosters
-------
INT RosterId (or GUID, or whatever type of ID you want)
DATETIME Week

RosterRecords
-------------
INT RosterId
INT EmployeeID (or however employees are identified)
DECIMAL Hours

RosterId in Rosters links to RosterId in RosterRecords. You then just have a pile of roster records, one per employee per week/roster. Now you don't need to create new tables for each week programmatically; you just register a new roster in Rosters and create its members in RosterRecords; you can do a join later to associate a roster with its records if needed in a query.

Jim Dagg
  • 2,044
  • 22
  • 29