Showing posts with label record. Show all posts
Showing posts with label record. Show all posts

Friday, February 17, 2012

Dependent Records

I want to delete a parent record.

Is there a simple call I could make that would tell me if there are dependent child records, without me having to hard code in all the child tables and manually calling each child table one at a time.

A .net framework call that that returned a Yes/No to a "Are there any dependent records?" sort of query, or better still if it told me the table the dependent record is in.

I would then know if I could delete the record.

I have referential integrity turned on and am using a Access 2000 .mdb, but will soon be upsizeing to SQL Server Express (the MSDE thingy).

I realise I could use the sledge hammer technique and let the Referential Integrity stop me, but a more polite approach would be better, and I am not sure if you can have Referential Integrity in SQL Express like you do in Access.

Warm regards

NeilReferential integrity in SQL Server Express is pretty much the same as Access, although you'll have more methods available for creating and maintaining the constraints (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_9183.asp).

If you want to delete all child records associated with a parent record, you can use cascading deletes (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_92ib.asp). This is not a good idea as a rule though, since most times you'll want the application to throw an exception if a parent record is deleted before the child records. In a typical application, you'd delete the child records first, then delete the parent record(s).

If this is a UI, I always like it when developers catch the RI exception if a user attempts to delete a parent, then displays a message such as "there are other records associated with the row you want to delete, all associated data will be deleted, are you sure this is OK?".

Hope this helps,
Josh Lindenmuth

Dependencies within a transaction

If i were to have a dynamic SQL transaction, where i want to insert a
record, and use the ID generated for this record, in a subsequent query in
the same transaction , how do i do it ?
Regards,
Chak.How are you generating the id? Is that an IDENITITY? or GUID? See @.@.IDENTITY
and SCOPE_IDENTITY() in SQL Server Books Online. Also see:
http://vyaskn.tripod.com/retrieve_g...ke_identity.htm
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Chakra" <chakra@.smnetserv.com> wrote in message
news:OnfQHsgJFHA.2628@.tk2msftngp13.phx.gbl...
> If i were to have a dynamic SQL transaction, where i want to insert a
> record, and use the ID generated for this record, in a subsequent query in
> the same transaction , how do i do it ?
> Regards,
> Chak.
>

Tuesday, February 14, 2012

Dependancy Information

Is there a way to update the dependency information
For example if I create a SP that references a table that does not exist no record will be put in sysdepends. If I later add this table can I update the dependancies to reflect this change?the only way I can think is to run Alter procedure script
in QA, or open the SP in Enterprise Manager and add a
blank line anywhere. This will update the sysdepends table.
>--Original Message--
>Is there a way to update the dependency information?
>For example if I create a SP that references a table that
does not exist no record will be put in sysdepends. If I
later add this table can I update the dependancies to
reflect this change?
>.
>