stored procedures - SQL - Check for consistency between the table data without using Cursors -
I am using SQL and I have 4 tables.
- tbl_project (project_id is the primary key
- tbl_task (Task_id as the primary key and project_ID included as a foreign key) < li> tbl_assignment (Includes assignment_id as primary key function_id as foreign key)
-
- One project may have one or more functions
- One assignment can be one or more assignments >
- In an assignment One or more documents may be
Now I have to write a stored procedure that will validate a project and return the verification result, where the form of project id parameter
- The project needs to check at least one task.
- All the tasks under this project have at least 1 assignment
- At least 1 document for this project / work
INMENT I have a floating table where I need it
Is there any way to implement this argument without using the cursor
/ div> < p>
You do not need a cursor to type this type of verification. These are three questions that do this:
No unused projects:
Choose p. * Tbl_projects p from external to join tbl_tasks t p.project_id = t.project_id where t.project_id is zero;
There is at least one assignment in the job: select
p. * Tbl_tasks t from the external join tbl_assignments a.task_id = t.task_id where a .task_id is zero;
All assignments have at least one document: select
p. * Tbl_assignments join a left outer tbl_documents at a.assignment_id = d.assignment_id where d.assignment_id is zero;
Comments
Post a Comment