Jeremy Stein - Brain
« cygwin rm doesn't work | MyEclipse – Add Spring Capabilities – Unable to access project's build-path » |
SQL Idempotent Insert
Sometimes you want to perform an idempotent insert in SQL. Here are some of the options (using SQL Server’s TSQL syntax):
- Check for existence first:
if not exists (select 'x' from tbl where key=val) insert into tbl values (val, ...)
- Delete and then insert (but this will fail if there are foreign keys depending on it
- Wrap the insert statement in something that can catch errors (like in a stored procedure). Ignore errors caused by the row already existing.
No Comments
Be the first to comment!
« cygwin rm doesn't work | MyEclipse – Add Spring Capabilities – Unable to access project's build-path » |
Leave a Reply