Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    blr india
    Posts
    2

    smart insert or update

    how come there aint no commant like insertUpdate - that takes the Pk cols, then the Pk values, then the other cols and the other vals - and if it finds a existing row with the Pk values then updates that with the other values else inserts a new row. For tables with a few columns this would be great.

    Some thing like this:
    insertUpdate (pkColName1, pkColName2, pkColName3, ...), (pkColValue1, pkColValue2, pkColValue3, ...) ( genColName1, genColName2, ...)
    (genColValue1, genColValue2, ... )

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171

    Re: smart insert or update

    Oracle 9i has a MERGE statement that does something quite like that, though you have to specify the conditions rather than rely on PK constraints (which would be nicer in some ways).

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002

    Re: smart insert or update

    Originally posted by tgkprog
    how come there aint no commant like insertUpdate
    there is in mysql

    INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
    [INTO] tbl_name
    SET col_name=(expression | DEFAULT), ...
    [ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Oct 2003
    Location
    blr india
    Posts
    2
    nice ! anything for MS SQL Server?

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    not that i'm aware of

    use T-SQL to see if the PK exists first, and UPDATE or INSERT accordingly
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •