开发者

Defining Child Tables and getting records from them

I am new to SQL. I am looking at creating a database where a value in one table is a pointer to another 'whole' table (not just a value in the other table ... but the table itself). How can one achieve this and how can one write an SQL statement to access data in the child table? I'll illustrate with the following tables

Project:

ID   Name   Site              Client          Progress
------------------------------------------------------
1    Bronx  99-Beans Street   Mr.Smith         **1 
2    Mandy  4-Apt Clinton     Mrs. Cross       **2
3    Ani    7-Magbo,Jos, NG   FRN, 9ja         **3

Bronx:

Task Description             Start        Finished   Handler
--------------------------------------------------------开发者_JAVA技巧-----
1    Remove Top-Soil         07:50:33     12:10:05   Jack
2    Break Ground            13:00:20     15:33:52   Grader
3    Spray Fertilizer        15:55:30     17:15:23   Suzie

Notice that the second Table takes its name from the Name Value of Project @ id=1. The Id could still serve this purpose, in which case, the table would be titled '1' ... which is rather odd, but at least this explains the kind of relationship the tables should have. Deleting a record in the 'Project' Table should also delete the associated Progress table(bearing the name of the record)*. How can one create & Query tables with this relationship in SQL?


In the project table you have to make sure that not only is the ID field unique but the Name field as well. Since you want to create tables in the database using the name field this would pose an issue if you had duplicates. Next I would make a call to the projects table from my program, read the table name, then pass that name to another query for the specific project. In the case where the specific table, Bronx, for instance is removed from the project table you could write a trigger in the project table that would say delete the project specific table listed in the Row column. Bottom line is only part of what you need done can occur in SQL while the rest should be managed in your program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜