易截截图软件、单文件、免安装、纯绿色、仅160KB

Merge SQL 2008

merge [target] t
using [source] s on t.id = s.id
when matched then update t.name = s.name, t.age = s.age -- use "rowset1"
when not matched then insert values(id,name,age) -- use "rowset2"
when source not matched then delete; -- use "rowset3"
MERGE dbo.table AS im --对比表
USING (SELECT * from dbo.table_MID with(nolock) ) AS src --源
ON im.ProductID = src. ProductID
WHEN MATCHED THEN
UPDATE SET im.ProductID = src. ProductID
,im.BrandName=src.BrandName
,im.ProductName = src.ProductName
,im.ProductType=src.ProductType
,indate=getdate()
WHEN NOT MATCHED THEN
INSERT (ProductID,BrandName,Series,ModelNumber,ProductName,ProductType,Category,indate)
VALUES (src.ProductID,src.BrandName,src.Series,src.ModelNumber,src.ProductName,src.ProductType,src.Category,src.indate)
WHEN NOT MATCHED BY SOURCE then delete;


相关文档:

ORACLE SQL语句优化


1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):
ORACLE的解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。如果有3个以上的表连接查询, 那就需要选择交叉表(intersection ......

sql server 定义主键

drop table father;
create table father(
 id int identity(1,1) primary key,
 name varchar(20) not null,
 age int not null
  
)
drop table mother;
create table mother(
 id int identity(1,1),
 name varchar(20) not null,
 age int not null,
 husban ......

.NET学习手记之:linq to SQL(二)


在Visual Studio 2008 中使用O/R设计器:
点添加项目,选择创建Linq to SQL项目,使用服务器资源管理器连接Northwind数据库,将Customers和Orders两个表拖到设计界面上,系统会自动创建app.config和Northwid.designer.cs,前者是配置连接数据库的连接字串;后者会生成一个继承自DataContext的类:NorthwindDataContext。 ......

一次插入多条信息(sql)

注释:只适合单表单列数据,
create database test
go
use test
go
create table users
(
:id int identity(1,1) primary key not null,
:name nvarchar(20)
)
go
create proc sp_Inserts
@Names nvarchar(4000)
as
declare @Name nvarchar(20),@ErrorSum int
:set @ErrorSum = 0
:begin tra ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号