sqlserver 2005

  • In my database I would like to create 10 tables(suppose) ,

    in that 1. sutdent details

    2. student marks

    3.student attendence

    4. student feesDetails

    Now I would like to update or delete a record from base table , the effects should be taken in child tables.

    for that how could I write a single query which is effecting on more tables .

    please help me

    Thanks in advance

  • Hi

    If your tables have a primary and foregin key for the student for each table then you could create a SP or query that would be something like:

    --//////////////////////////////////////////

    declare @StudentID as int

    select @StudentID = 23

    delete from tblStudent where intStudentID = @StudentID

    delete from tblStudentSubjects where intStudentID = @StudentID

    delete from tblStudentDetails where intStudentID = @StudentID

    delete from tblStudentTasks where intStudentID = @StudentID

    The other way is to setup your referencial integrity between the tables and let the delete do a cascading delete

    Thanks

    Kevin

  • Hi

    just try for Triggers.

  • Am with Jaypee.Better go for trigger 😀

  • I would have to disagree with trigeers,

    set up PK->FK references in your database, and create one procedure to do the data manipulation as Kevin suggested.

  • Triggers are great for maintaining data integrity when it can't be maintained through the normal means. Here, however, you have a very easy way to use standard data constraints. The FK constraint with cascade delete does very nicely.

    I agree with Kevin and steveb on this one.

  • If we talk about efficiency, we talk about using best practices. Abandoning the use of practice for an alternative method is tantamount to adding extra load.

    With this said, I believe the use of delete cascade on tables with PK - FK relationship is best for situations like this - in my view, it is far easier to get the problem solved this way than the other.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply