Subject: contraints and relationships
Posted By: zouky Post Date: 9/21/2004 11:27:22 AM
dear expert

i am using MS SQL2000 as my database, i design my database and its particular tables by using the SQL Enterprise manager.
then i set up each attirbute by declaring its data type, not null.....

ok, now the problem is i do this database design in advanced ways before the real coding step into. so, if i already establish
their relationship and constraints, what should i do in the coding side? is it need to do it in promgrammatic way to specify
the PK and FK constraint (refrential integrity) one by one or everything is being settle by establishing their relationship on
the database diagram?

futhermore, there's something call SQL script, what's the main deffirent between triggers, stored procedure when in what kind
of situation should calling the apporpriate events between SQL scrip[t, triggers and stored proceudre?

Reply By: bmains Reply Date: 9/21/2004 11:49:31 AM
Hey,

You can reestablish the constraint by creating a DataRelation.  You can find this in the MSDN and on the web.

Triggers execute when data is inserted, updated, and deleted only.  They can do whatever you want, but only on these events.  Stored procedures you have to call (in your code).  You can't call triggers in your code; they are only available on the database side.

Brian
Reply By: zouky Reply Date: 9/22/2004 9:59:19 AM
well, i just review it at MSDN and gain some understanding on DB structure.

I would like to use Treeview (namespace microsoft.web.UI.webcontrols)
as my interface. let say there are treenode A,B and C. If i check on treenode A, then this will perform an action on the related table
resides on the MSSQL 2000 (let say the table name is Alpha, and its field's (Treenode A,B,C)attribute is boolean type (check for true;uncheck for false, default is set to false).

i know it is something dealing with DML side. how do i doing this by using "Update...Set..." this query statemnt? how to define thier relation......and what should i do if i checked on particular check box for the treenode??

for this treeview is actually using by the admin site for granting the privilege to the user purpose.

thank you for reply on previous question.


Reply By: bmains Reply Date: 9/22/2004 10:44:04 AM
Hey,

You can create a relationship sure, for update statement, say you got t1, t2, t3, t3 contains a fk to t2, t2 contains a fk to t1.

Use three updates to update t1, t2, then t3.  Depending on what you want triggers for, you may be able to do that too.

What do you want to do with the treeview, to then update the field?  Most likely, if you are at the second-node level (data in t2), whatever changes you make don't typically involve the primary key, and won't be affected by t1 or t3.  If there is a PK change, then you could use cascading which automatically changes the values in the FK tables.

Not sure what you mean about the checkbox thing?

Brian

Brian
Reply By: zouky Reply Date: 9/24/2004 7:05:02 AM
dear brian

one very important thing to ask, there's no boolean datatpye in MS sql server 2000. what should i do with if i checked on the checkbox, it will change the column value from false ino true.

any web page or KB regrading this topic? should be something related with forrm+treeview+class checkboxex

thank you


Reply By: Hal Levy Reply Date: 9/24/2004 8:50:55 AM
For some reason they changed bool to bit...

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply By: zouky Reply Date: 9/24/2004 10:43:35 AM
yeah...but how to set the column data type with bit? what's the default value for it?

Reply By: Hal Levy Reply Date: 9/24/2004 11:05:55 AM
Uh.. Bit is always either 1 or 0.. I believe you can use true/false also.

Hal Levy
I am here to help you, not do it for you.
Reply By: zouky Reply Date: 9/24/2004 11:20:20 AM
so, set the default value=0 as false, after check it the value will be +1; then become true...

but this condition where should i put, is it stored procedure, triggers or inside the query builder pane?

Reply By: Hal Levy Reply Date: 9/24/2004 11:23:44 AM
sorry- I don't understand the question.

Hal Levy
I am here to help you, not do it for you.
Reply By: zouky Reply Date: 9/24/2004 11:31:00 AM
if i know the logic flow to perform an update for this checkbox action, where should i put my coding on? is it in stored proceudre, triggers or inside the command.text?

Reply By: Hal Levy Reply Date: 9/24/2004 1:30:45 PM
That's an architecture decision. You can code in any way you want. Personally, I do all of my business work in the business tier.

Hal Levy
I am here to help you, not do it for you.

Go to topic 19714

Return to index page 765
Return to index page 764
Return to index page 763
Return to index page 762
Return to index page 761
Return to index page 760
Return to index page 759
Return to index page 758
Return to index page 757
Return to index page 756