Checking if a record existsin table b4 inserting it to another table

Last Post 22 Sep 2008 05:50 AM by SwePeso. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
New Member
New Member

15 Sep 2008 01:21 PM
Hi Guys
If anyone can help me with this it would be greatly appreciated.
K here is what's happening.I am supposed to check if a student exists in the STUDENT table and then check if a module exists in the MODULE table.if they exist in both tables I must add the student(StudentNumber) and the module(ModuleCode) to the STUDENTMODULE table(register the student).
How do i do this plz help
New Member
New Member

16 Sep 2008 12:32 AM
Here is the logic outline:

if exists (select 1 from Student where StudentID=@Student)
and exists (select 1 from Module where ModuleID=@Module)
insert StudentModule..... @Student, @Module

Let us know if helpful.

Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQL Server Training, SSAS, SSIS, SSRS:
New Member
New Member

22 Sep 2008 05:50 AM
If you use foreign key contraints, you will be notified when a record has no match in outer tables.

Acceptable Use Policy