December 27, 2018 at 11:12 am
I'm converting a database to sql server from sql anywhere. The tables use a trigger to update a column that has a timestamp. I'm using a cursor to scan the inserted table, capture the primary keys and update the production table. The tables are small so the cursor is acceptable. This works fine except for those few tables without primary keys. I'm considering referencing non key columns in the inserted table and using those to try to match the production table. This is not perfect but I can't think of another way to do this. Alternatives?
When the snows fall and the white winds blow,The lone wolf dies but the pack survives.
Once you've accepted your flaws, no one can use them against you.
December 27, 2018 at 11:24 am
fizzleme - Thursday, December 27, 2018 11:12 AMI'm converting a database to sql server from sql anywhere. The tables use a trigger to update a column that has a timestamp. I'm using a cursor to scan the inserted table, capture the primary keys and update the production table. The tables are small so the cursor is acceptable. This works fine except for those few tables without primary keys. I'm considering referencing non key columns in the inserted table and using those to try to match the production table. This is not perfect but I can't think of another way to do this. Alternatives?
Based on your description, I'd still say that the cursor is not acceptable.
Does the table contain one or more columns which uniquely identify a single row?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
December 27, 2018 at 5:34 pm
fizzleme - Thursday, December 27, 2018 11:12 AMThe tables are small so the cursor is acceptable.
No, it's actually not. 😉 I hope you don't find that out the hard way.
As for the tables with no Primary Key, if there's absolutely nothing to uniquely identify the row, consider using INSTEAD OF triggers... and not using cursors in the triggers. They're a bit of a pain in the butt so it would be worthwhile to add an IDENTITY column to the tables even if the only thing you used it for was to do your trigger-driven updates in an efficient manner.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2018 at 8:24 am
It's hard to know what else you can do without seeing some code and data. I would agree a cursor is not needed. You ought to be able to update the table directly from inserted without a cursor.
December 30, 2018 at 3:59 pm
fizzleme - Thursday, December 27, 2018 11:12 AMI'm converting a database to SQL server from SQL Anywhere. The tables use a trigger to update a column that has a timestamp. I'm using a cursor to scan the inserted table, capture the primary keys and update the production table. The tables are small so the cursor is acceptable. This works fine except for those few tables without primary keys. I'm considering referencing non-key columns in the inserted table and using those to try to match the production table. This is not perfect but I can't think of another way to do this. Alternatives?
If it does not have a key, then it is not a table, by definition. You can also use a DEFAULT CURRENT_TIMESTAMP clause on this column ...
Please post DDL and follow ANSI/ISO standards when asking for help.
December 31, 2018 at 5:35 am
jcelko212 32090 - Sunday, December 30, 2018 3:59 PMfizzleme - Thursday, December 27, 2018 11:12 AMI'm converting a database to SQL server from SQL Anywhere. The tables use a trigger to update a column that has a timestamp. I'm using a cursor to scan the inserted table, capture the primary keys and update the production table. The tables are small so the cursor is acceptable. This works fine except for those few tables without primary keys. I'm considering referencing non-key columns in the inserted table and using those to try to match the production table. This is not perfect but I can't think of another way to do this. Alternatives?If it does not have a key, then it is not a table, by definition. You can also use a DEFAULT CURRENT_TIMESTAMP clause on this column ...
Amen to both!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply