【SQL 语句问题】判断一行,如不存在则插入,MSSQL里面可以用一个语句完成么?
MySQL里面有   replace   into   这个语句,就是完成这个功能的,MSSQL里面有类似的语句吗? 
 如果不支持,用存储过程来做应该效率高一点吧,怎么写呢? 
 多谢!
------解决方案--------------------create proc sp_test 
 as     
 if not exists (select * from 表名 where id=100)   
 insert into 表名(id) select 100   
 go
------解决方案--------------------如果是多条操作性SQL语句,需要使用事务保证数据处理的完整性。   
 如:     
 create proc sp_test 
 as     
 set xact_abort on      
 begin tran   
 if not exists (select * from 表名 where id=100)   
 insert into 表名(id) select 100     
 if not exists (select * from 表名 where id=200)   
 insert into 表名(id) select 200   
 commit tran   
 go
------解决方案--------------------if not exists (select * from 表名 where id=100)   
 insert into 表名(id)  
 else   
 update ........     
 只要在插入之前做个判断就可以了。。看看是否有记录。。
------解决方案--------------------可以在存储过程中,也可以直接在查询分析器中执行。   
 是可以直接执行的SQL语句。
------解决方案--------------------報的什麼錯誤?   
 試下這個     
 Create Table TEST(ID Int, Name Varchar(10)) 
 If Not Exists (Select ID From TEST Where ID = 1) 
 	Insert TEST Values(1,  'A ')