Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Update vs REPLACE
Message
From
13/12/2000 02:08:00
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00452757
Message ID:
00452763
Views:
26
>I am modifying an application that has many instances of multiple
>REPLACE commands to update tables, such as
>
>
>replace field1 with "value1"
>replace field2 with "value2"
>replace field3 with "value3"
>

>
>I want to speed this application up. So I considered:
>
>UPDATE MyTable;
> SET Field1 = "Value1";
>   Field2 = "Value2"
>   Field3 = "Value3"
>

>
>Since REPLACE starts at the first record, the 3 separate REPLACE commands
>therefore make 3 passes through the table, while the SQL Update goes through
>the table only once.
>
>However, the Hackers Guide says the SQL Update is slower than REPLACE. Isnt
>REPLACE 'old school' and SQL 'optimized'?
>
>What are the Pros and Cons of each method?
>
>Thanks

First of all, you'd be better off with
REPLACE ;
  field1 WITH "value1", ;
  field2 WITH "value2", ;
  field3 WITH "value3", ...
  IN TableAlias
Second, the default scope of REPLACE is NEXT 1, so it acts on the record at the record pointer position - no pointer manipulation or optimization required, should be faster than UPDATE - SQL. Get used to using the IN clause, which prevents the xBASE "feature" of REPLACE not working if the table to be updated is not the current work area, and you're at EOF() in the current work area.

UPDATE - SQL is more "modern" in that it is SQL-style, the only type of update that SQL backends support, so it makes some sense to get used to that type of syntax. It is also a much more powerful command than REPLACE if you want to work with multiple records, as you can use SQL syntax and set logic to select records for updating.

Each command has its place, IMHO.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform