|
NihilCredo posted:Couple of SQL Server questions: 1) Think of it as SQL Server just trying to minimize the amount of deadlocks on a possible resource. Say you had both foreign keys on Widgets tying back to Users - if a Widget was created and updated by the same user, then each foreign key fires when that user is deleted. You'd have plenty of deadlocks if that user created & updated more than 1 widget. Even if cascade was just on 1 foreign key, the constraint will still check the Widgets table for a reference, but delete and update will request an exclusive lock, and most likely horrid performance. Not sure of your exact structure, but would a on update/ on delete trigger referencing a stored proc in Users work for you? (I'd say have the proc update/delete from Widgets where UserID = CreatedBy or UserID = UpdatedBy) 2) Outside of saving a table called "base_template" in model, but otherwise no magic bullet I've encountered. I've seen a truckload of dynamic SQL procs build a create table statement out of a dictionary, but it's a mess to read and debug. 3) I've seen plenty of cases where a currency was normalized into it's own table - it's just good design and saves a lot in storage. I'd say the best guidelines I see my colleagues following is this: is the character data static/controlled change or highly dynamic? If static, go for normalizing into a table. For example, if you have a column for a custom MSMQ message type in a .Net app and you have 10,000 different types, it'd still be worth it. Just about any flavor of SQL will chew through 100k rows with ease outside of BLOBs. But if you're tracking a few million different varchar values and your table isn't too big (under 100 GB), I wouldn't sweat it too much.
|
# ¿ Jun 4, 2015 03:19 |
|
|
# ¿ Apr 29, 2024 02:37 |
|
NihilCredo posted:Thanks a lot for the answers! Sorry, I misunderstood what you were trying to do when I mentioned the trigger on Users. After I thought about it more, it seems like you're trying to update/delete the user from Users when a widget is updated or deleted? At least, that's what CASCADE would do on a foreign key on a Widgets column referencing Users. Outside of that, I'd suggest maybe doing a stored proc to control the delete when you want to delete the user ID - set all of the references to the User ID to null, then toss the row from Users. Regarding telling SQL to ignore the cascade problem, I tried it out and had the same error. When I read that more, it seems like that protection is built in to prevent a big screw up by the relational engine and the algebrizer? I'm guessing that when it translates the commands into code to execute on the tables, something must be very weird when you get multiple cascade patgs
|
# ¿ Jun 5, 2015 14:35 |