Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I'm developing a sql database, but I have faced with a problem in relation of tables. Assume that we have a table named "TASK" that contains these fields: id, TaskName, Type, startDate, endDate. Each Task has different attributes and details. So I have to create a table for each Type of task and connect Task to these Tables.

My question is how can I connect "Task" to other tables?

If you know a better way.

Please help me.

Thanks for your answers.
Posted
Updated 2-Feb-11 0:05am
v3
Comments
shakil0304003 2-Feb-11 6:00am    
Not clear!!!
Chris Maunder 2-Feb-11 6:30am    
"Each Task has different attributes and details": What do you mean? Are there more fields depending on the type of Task?

You need to implement a foreign key constraint in your Task table.

Take a look at this page[^] from MSDN and also follow the links on the page. In the diagram The 'SalesOrderHeader' would be your Task table and the 'SalesPerson' would be the new table you should create for TaskType.

TaskType should contain at least TaskTypeID and TaskTypeDescription columns.
TaskTypeID should be the Primary Key NOT NULL. It should be an Integer datatype column and you can make it an Identity column if you wish.
Change the Type column in your Task table to be an Integer datatype.

Then follow the pattern shown in the link.
 
Share this answer
 
Comments
mojtaba pirveisi 2-Feb-11 8:54am    
Thnk for your answers but I know how to create relationship between tables , My problem is that each Task has different attributes , for example , task number 1 is "typing" , I want to know how many pages has been typed so far , which font has been used and etc . Task number 2 is "Image Editing" , I want to what the progress is ( for example 35%) , whether image has been cropped (yes or no ) and etc . Ss you can see I have to create different table because of different column for each task . If I have a table for "Task" , one for "Typing" and another for "Image Editing" , How can I connect these two tables to "Task" ?
Thanks again .
Henry Minute 2-Feb-11 9:24am    
The first thing that occurs to me is that if you are able to enumerate all of the possible categories of task you might adopt a similar structure to that used in an Accounting program where there is a main category (e.g. Stationery) with sub categories (Pens, Notepads, Paperclips etc...) each category having an ID. Even with that you still have the problem of many tables because of the different attributes.

Another approach might be to follow the design of a typical 'Time Sheet' application where again there is the main Task with ID and designated Sub-Tasks with IDs but the rest is more free-form.

If you think that you could model your requirements using an Object Oriented language (A Base Class with derived classes adding to the properties of that 'parent' for each sub-task) then the article at http://www.sqlteam.com/article/implementing-table-inheritance-in-sql-server might be of use.

Sorry to not be more help. If I think of anything else I'll come back to you.
mojtaba pirveisi 2-Feb-11 11:10am    
Thanks . That helps me a lot .
You can create one table for attributes and store all the attributes in the single table for a given task.
 
Share this answer
 
v2
you need to create a table where you store tasks and a table where you store different types of tasks. In the taks table (1st) you set the ID of row of the specific tasktype (2nd table)

For a tutorial about relationships:

http://www.functionx.com/sql/Lesson11.htm[^]
 
Share this answer
 
Comments
Henry Minute 2-Feb-11 6:18am    
That would be an excellent link were it not for the fact that it deals with MySql and therefore gives incorrect syntax for SqlServer. This will confuse the OP who is obviously a beginner.
AschB 2-Feb-11 6:44am    
Whoops my bad. Sorry

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