在SQL Server 删除重复数据
删除数据库表中某一字段的重复纪录,只想保留一条记录可用以下方法:
执行以下语句:
declare @max integer,@id varchar(18) --此处变量类型根据字段类型设置
declare cur_rows cursor local for select 字段,count(*) from 表名group by 字段 having count(*) > 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
delete from 表名where 字段 = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0
相关文档:
分布式查询
OPENROWSET
从Excel取数据
SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=d:\1.xls',[Sheet1$])
从Oracle取数据
SELECT * from OPENROWSET('MSDAORA.1','NetServiceName ......
--该表保存结果
create table c(c1 tinyint, c2 tinyint, c3 tinyint, c4 tinyint, c5 tinyint, c6 tinyint, c7 tinyint, c8 tinyint, c9 tinyint, c10 tinyint, c11 tinyint, c12 tinyint, c13 tinyint, c14 tinyint, c15 tinyint, c16 tinyint, c17 tinyint, c18 tinyint, c19 tinyint, c20 tinyint, c21 tinyint, c22 t ......
dim conn,connstr
Set conn = Server.CreateObject("ADODB.Connection")'创建一个数据库链接对象conn,方便后面调用
connstr="Provider=SQLOLEDB;Data Source=(local);Initial Catalog=111;User ID=sa;Password=1234;" '创建一个数据库的recordset对象,方便以后调用
conn.Open connstr'打开数据库 ......
Access 的 SQL 中,计算相应编号的记录之间 加 减 的查询命令
例如 计算ID为 6 的 合计 减去 ID 为 2、3、4 以及加上 ID 为 5 的合计
SELECT SUM(R) AS 结果
from
(
SELECT 合计 AS R from T1 WHERE (ID = 6) UNION
SELECT -合计 AS R from T1 WHERE (ID = 2) UNION
SELECT -合计 AS R f ......
一、基础
1、说明:创建数据库
CREATE DATABASE database-name
2、说明:删除数据库
drop database dbname
3、说明:备份sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- 开始 备份
BACKUP DATABASE pubs TO testBack
4、说 ......