当前位置: 代码迷 >> Sql Server >> SQL中 merge语句 没有where子句吗,Oricle都有解决方法
  详细解决方案

SQL中 merge语句 没有where子句吗,Oricle都有解决方法

热度:11   发布时间:2016-04-27 13:57:16.0
SQL中 merge语句 没有where子句吗,Oricle都有
我在网上看到oricle的merge例子,放到sql server 2008中就不行,好象SQL SERVER 2008 中merge不能
添加where 子句 特来向达人求证。

------解决方案--------------------
不懂帮顶
------解决方案--------------------
没用到,帮顶.
------解决方案--------------------
没有,ORACLE不是SQL SERVER,两者还是有许多不同的。
------解决方案--------------------
merge 是SQL2008新增加的用法
F1中:
SQL Server 2008 联机丛书(2009 年 7 月)
 
MERGE (Transact-SQL) 发送反馈 
请参阅
 全部折叠全部展开 语言筛选器: 全部语言筛选器: 多个语言筛选器: Visual Basic语言筛选器: C#语言筛选器: C++语言筛选器: J#语言筛选器: JScript 
 
 Visual Basic(Declaration) 
 C#
 C++
 J#
 JScript

根据与源表联接的结果,对目标表执行插入、更新或删除操作。例如,根据在另一个表中找到的差异在一个表中插入、更新或删除行,可以对两个表进行同步。

 Transact-SQL 语法约定

语法
 
[ WITH <common_table_expression> [,...n] ]
MERGE 
[ TOP ( expression ) [ PERCENT ] ] 
[ INTO ] <target_table> [ WITH ( <merge_hint> ) ] [ [ AS ] table_alias ]
USING <table_source> 
ON <merge_search_condition>
[ WHEN MATCHED [ AND <clause_search_condition> ]
THEN <merge_matched> ] [...n ]
[ WHEN NOT MATCHED [ BY TARGET ] [ AND <clause_search_condition> ]
THEN <merge_not_matched> ]
[ WHEN NOT MATCHED BY SOURCE [ AND <clause_search_condition> ]
THEN <merge_matched> ] [...n ]
[ <output_clause> ]
[ OPTION ( <query_hint> [ ,...n ] ) ]
;

<target_table> ::=

[ database_name . schema_name . | schema_name . ]
target_table
}

<merge_hint>::=
{
{ [ <table_hint_limited> [ ,...n ] ]
[ [ , ] INDEX ( index_val [ ,...n ] ) ] }
}

<table_source> ::= 
{
table_or_view_name [ [ AS ] table_alias ] [ <tablesample_clause> ] 
[ WITH ( table_hint [ [ , ]...n ] ) ] 
| rowset_function [ [ AS ] table_alias ] 
[ ( bulk_column_alias [ ,...n ] ) ] 
| user_defined_function [ [ AS ] table_alias ]
| OPENXML <openxml_clause> 
| derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ] 
| <joined_table> 
| <pivoted_table> 
| <unpivoted_table> 
}

<merge_search_condition> ::=
<search_condition>

<merge_matched>::=
{ UPDATE SET <set_clause> | DELETE }

<set_clause>::=
SET
{ column_name = { expression | DEFAULT | NULL }
| { udt_column_name.{ { property_name = expression
| field_name = expression }
| method_name ( argument [ ,...n ] ) }
}
| column_name { .WRITE ( expression , @Offset , @Length ) }
| @variable = expression
| @variable = column = expression
| column_name { += | -= | *= | /= | %= | &= | ^= | |= } expression
| @variable { += | -= | *= | /= | %= | &= | ^= | |= } expression
| @variable = column { += | -= | *= | /= | %= | &= | ^= | |= } expression
} [ ,...n ] 

<merge_not_matched>::=
{
INSERT [ ( column_list ) ] 
{ VALUES ( values_list )
| DEFAULT VALUES }
}

<clause_search_condition> ::=
<search_condition>

<search condition> ::=
{ [ NOT ] <predicate> | ( <search_condition> ) } 
  相关解决方案