下面是我的原句: INSERT INTO @TempJz (上班日期,机组,完成数,生产指标,班次) select A.*,C.每天产量,D.班次 from (select 生产日期,机组,sum(完成数) 完成数 from dbo.BomJobSchedule1 where 机组 like 'B%' and 生产日期='2004-3-31' group by 生产日期,机组) A inner join dbo.C_jz B on B.机组编号 = A.机组 inner join dbo.Order_jq C on C.机器编号 = B.机器编号 left join dbo.C_Jz_Kcb D on D.上班日期 = A.生产日期 AND D.机组编号 = A.机组
把字段名称改成相同试一下: INSERT INTO @TempJz (上班日期,机组,完成数,生产指标,班次) select A.*,C.每天产量 生产指标,D.班次 from (select 生产日期 上班日期,机组,sum(完成数) 完成数 from dbo.BomJobSchedule1 where 机组 like 'B%' and 生产日期='2004-3-31' group by 生产日期,机组) A inner join dbo.C_jz B on B.机组编号 = A.机组 inner join dbo.Order_jq C on C.机器编号 = B.机器编号 left join dbo.C_Jz_Kcb D on D.上班日期 = A.上班日期 AND D.机组编号 = A.机组
--用 * 没问题--测试--测试数据 create table aa(a int,b int,c int) insert aa select 1,2,3 union all select 2,3,4 union all select 2,3,4 union all select 2,3,4create table bb(b int) insert bb select 1 union all select 2 union all select 3create table cc(b int) insert bb select 1 union all select 2 union all select 3 godeclare @t table(aa int,bb int,cc int,dd int,ee int) insert @t(aa,bb,cc,dd,ee) select a.*,b.b,c.b from(select a,b,c=sum(c) from aa group by a,b )a join bb b on a.b=b.b left join cc c on a.b=c.bselect * from @t go--删除测试 drop table aa,bb,cc/*--测试结果 aa bb cc dd ee ----------- ----------- ----------- ----------- ----------- 1 2 3 2 NULL 2 3 12 3 NULL 1 2 3 2 NULL 2 3 12 3 NULL(所影响的行数为 4 行) --*/
我用邹建的代码测试也不出错,一换我的那句话就出错了,WHY?
为什么我复制表结构来新建一个表aaaa 然后用这样的语句insert into aaaa select * from dbo.BomJobSchedule1 出现这样的错误: 插入错误: 列名或所提供值的数目与表定义不匹配。 可列明明是一样,看来邹建的猜测是对的,这个表损坏了,请问可以修复吗?
USE MASTER GOsp_dboption '你的数据库名', 'single user', 'true' Go--修复整个数据库 DBCC CHECKDB('置疑的数据库名',REPAIR_REBUILD) Gouse 你的数据库名--修复指定表 DBCC CHECKTABLE('表名',REPAIR_REBUILD) go sp_dboption '你的数据库名', 'single user', 'false' Go
--杀掉它/* 关闭用户打开的进程处理 */ use master goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[p_killspid] GOcreate proc p_killspid @dbname varchar(200) --要关闭进程的数据库名 as declare @sql nvarchar(500) declare @spid nvarchar(20) declare #tb cursor for select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname) open #tb fetch next from #tb into @spid while @@fetch_status=0 begin exec('kill '+@spid) fetch next from #tb into @spid end close #tb deallocate #tb go--用法 exec p_killspid '数据库名'
2002-09-04 12:50:17.21 server SqlDumpExceptionHandler: 进程 2020 发生了严重的异常 c0000005 EXCEPTION_ACCESS_VIOLATION。SQL Server 将终止该进程。
2002-09-04 12:50:17.64 server SQL Server 将终止。发生了严重的异常 c0000005。
如果没有启动sql agant服务,这SQL SERVER服务器需要人工手动启动,如果启动了了SQL AGANT,SQL SERVER服务器会在3秒以后自动恢复。
但是可以不断的发起这样的包达到拒绝服务的目的,同时由于该协议是UDP协议,可以轻易的使用IP欺骗发起攻击,在还可以使用广播一次使得多个SQL SERVER受到攻击。测试环境:
SQL SERVER 2000+SP2
WINDOWS 2000 SERVER+SP3,ADV SERVER+SP3,professional+SP2可能是你的网络问题
ODBC: 消息 0,级别 19,状态 1
SqlDumpExceptionHandler: 进程 71 发生了严重的异常 c0000005 EXCEPTION_ACCESS_VIOLATION。SQL Server 将终止该进程。
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData (CheckforData()).
服务器: 消息 11,级别 16,状态 1,行 0
一般性网络错误。请检查网络文档。
ODBC: 消息 0,级别 16,状态 1
通讯连结失败连接中断网络错误?感觉迷惑,其它存储过程、触发器、表的操作都可以运行,为什么用这个就提示
连接错误?
INSERT INTO B
SELECT A.*,C.字段1,C.字段2
FROM A inner join C on C.ID = A.ID
应该是你TEMPDB出问题了,或者你没有打SP3。
不准那样写INSERT语句
INSERT INTO @TempJz (上班日期,机组,完成数,生产指标,班次)
select A.*,C.每天产量,D.班次
from (select 生产日期,机组,sum(完成数) 完成数 from dbo.BomJobSchedule1
where 机组 like 'B%' and 生产日期='2004-3-31'
group by 生产日期,机组) A inner join dbo.C_jz B on B.机组编号 = A.机组
inner join dbo.Order_jq C on C.机器编号 = B.机器编号
left join dbo.C_Jz_Kcb D on D.上班日期 = A.生产日期 AND D.机组编号 = A.机组
INSERT INTO @TempJz (上班日期,机组,完成数,生产指标,班次)
select A.*,C.每天产量 生产指标,D.班次
from (select 生产日期 上班日期,机组,sum(完成数) 完成数 from dbo.BomJobSchedule1
where 机组 like 'B%' and 生产日期='2004-3-31'
group by 生产日期,机组) A inner join dbo.C_jz B on B.机组编号 = A.机组
inner join dbo.Order_jq C on C.机器编号 = B.机器编号
left join dbo.C_Jz_Kcb D on D.上班日期 = A.上班日期 AND D.机组编号 = A.机组
create table aa(a int,b int,c int)
insert aa select 1,2,3
union all select 2,3,4
union all select 2,3,4
union all select 2,3,4create table bb(b int)
insert bb select 1
union all select 2
union all select 3create table cc(b int)
insert bb select 1
union all select 2
union all select 3
godeclare @t table(aa int,bb int,cc int,dd int,ee int)
insert @t(aa,bb,cc,dd,ee)
select a.*,b.b,c.b
from(select a,b,c=sum(c) from aa group by a,b
)a join bb b on a.b=b.b
left join cc c on a.b=c.bselect * from @t
go--删除测试
drop table aa,bb,cc/*--测试结果
aa bb cc dd ee
----------- ----------- ----------- ----------- -----------
1 2 3 2 NULL
2 3 12 3 NULL
1 2 3 2 NULL
2 3 12 3 NULL(所影响的行数为 4 行)
--*/
然后用这样的语句insert into aaaa select * from dbo.BomJobSchedule1
出现这样的错误:
插入错误: 列名或所提供值的数目与表定义不匹配。
可列明明是一样,看来邹建的猜测是对的,这个表损坏了,请问可以修复吗?
GOsp_dboption '你的数据库名', 'single user', 'true'
Go--修复整个数据库
DBCC CHECKDB('置疑的数据库名',REPAIR_REBUILD)
Gouse 你的数据库名--修复指定表
DBCC CHECKTABLE('表名',REPAIR_REBUILD)
go
sp_dboption '你的数据库名', 'single user', 'false'
Go
我想分离都不行,用你这个sp_dboption命令也失败,我到现在都搞不清是哪三个连接在
关闭用户打开的进程处理
*/
use master
goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GOcreate proc p_killspid
@dbname varchar(200) --要关闭进程的数据库名
as
declare @sql nvarchar(500)
declare @spid nvarchar(20) declare #tb cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open #tb
fetch next from #tb into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #tb into @spid
end
close #tb
deallocate #tb
go--用法
exec p_killspid '数据库名'
不过我看结果可能也是一样,所以真是让我莫名奇妙