发信人: chedong()
整理人: chedong(1999-07-08 20:51:04), 站内信件
|
问: 使用ANSI style outer join出现Msg 301, Level 16, State 1: Query co ntains an illegal outer-join request.的出错信息如何解决?
答: 在以下两种状况下会出现此出错信息:
1、此Query包含了五个以上的Table
2、Outer table包含了25列以上的数据
解决方法为:在执行out join之前先执行DBCC Traceoff(320)或安装Service pa ck 1以后的版本。
问:为何将一个在ISQL/W中可执行正常的Script写成stored procedure后,执行 此stored procedure就会有问题并且出现:Msg 202, Level 11, State 2 "Inte rnal error -- Unable to open table at query execution time." 的出错信息 ,如何解决?
答: 如果此stored procedure包含了下列各项:
1、以CREATE TABLE建permanent table
2、Drops在此stored procedure中建立的permanent table
3、建temporary table
4、在temporary table中宣告cursor
5、Drops在此stored procedure中建立的temporary table
解决方法为:采取下列任一方式,再重建stored procedure。
1、使用“SELECT INTO” statement建permanent table
2、避免使用“DROP TABLE”,或是只drop permanent table或只drop temporar y table。
3、将DECLARE CURSOR statement以括号包含在EXEC()中
4、建立stored procedure时使用WITH RECOMPILE参数或是执行时使用 WITH REC OMPILE选项。
问:在一个stored procedure中建立一个table并且使用DECLARE CURSOR statem ent参照到此table会出现Msg 202, Level 11, State 2 "Internal error -- Un able to open table at query execution time." 的出错信息,如何解决?
答: 1、执行stored procedure之前先将table建好。
2、将DECLARE CURSOR statement以括号包含在EXEC()中,例如:EXEC("DECLARE hC CURSOR FOR select * from pubs")。
问:对database设定"Columns Null by Default"选项,并使用如下的statement :reate table test(column1 varchar(12)
CONSTRAINT mykey PRIMARY KEY (column1, column3),
column2 varchar(2),
column3 varchar(2))?
却出现:Msg 8111, Level 16, State 0
Attempting to define PRIMARY KEY constraint on nullable column in tabl e <table name>, 如何解决?
答: 1、取消"Columns Null by Default"选项。
2、将primary key定义在所有column之后,如将上述statement改成:
create table test(column1 varchar(12),
column2 varchar(2),
column3 varchar(2),
CONSTRAINT mykey PRIMARY KEY (column1, column3))
问: 建立stored procedure时,出现error 1203的出错信息,并且client 端 的 connection可能也被中止?
答: 如果您在stored procedure中使用”create table” 建立一个table,并且 query中使用DISTINCT及ORDER BY但SELECT lists违反ANSI rules,就可能出现此 出错信息,请避免违反ANSI rules,z0如:
CREATE PROCEDURE sp_authors AS
CREATE TABLE #x (a int)
SELECT DISTINCT au_lname
FROM authors
ORDER BY au_lname, au_fname
GO
问: 在一个transaction中,update某个table中的数据后,再对同一table执行 Select statement并且此Select statement 包含ORDER BY DESC,出现“Caller of lock manager is incorrectly trying to unlock an unlocked object. s pid=%d locktype=%d dbid=%d lockid=%Id”出错信息,如何解决?
答: 如果此table有建立clustered index,并且有为update statement的WHERE 条件中的column建立nonclustered index。可使用下列任一方式解决;
1、将clustered index改成nonclustered index
2、将ORDER BY中不要使用DESC
3、将update statement的WHERE条件中的column建立 nonclustered index移除
4、将包含update及select的transaction移除。
问: 在EXISTS的条件中使用ANSI JOIN及correlated subquery,如
IF EXISTS (SELECT * FROM publishers
JOIN titles ON titles.pub_id = publishers.pub_id
WHERE (SELECT COUNT(*) FROM titleauthor
WHERE titleauthor.title_id = titles.title_id) > 1)
BEGIN
PRINT 'Exists'
END
出现error 403: Invalid operator for datatype op: UNKNOWN TOKEN type: v archar,如何解决?
答: Where子句中使用join的方式或升级至SQL Server 6.5 Service Pack 2以后 的版本。
问: 在ISQL/W下执行select convert(int,'A'),为何会出现下列出错信息,
Msg 249, Level 16, State 1
Syntax error converting CHAR value 'A' to an INT4 field? 如何处理?
答:因为“A”是字母而不是数字如“1”,“2”,“3”,┅所以无法像select co nvert(int,‘1')一样转换,如果要将字母转换成ASCII值请使用ascii()函数,如 select ascii(‘A')将传回65。
问: 如果dateadd函数使用在select statement中的group by子句,为何group的 功能好像没有作用?
答: 如果日期的数据类型为smalldatetime,会发生此状况,解决方式为将日期 的数据类型定为datetime或是以convert函数将smalldatetime转换成datetime, 如您的Script本为:
SELECT DATEADD(hh,-1,date_col), SUM(int_col)
FROM Test
GROUP BY DATEADD(hh,-1,date_col)
GO
则将script改成:
SELECT DATEADD(hh,-1,CONVERT(DATETIME,date_col)), UM(int_col)
FROM Test
GROUP BY DATEADD(hh,-1,CONVERT(DATETIME,date_col))
GO
问: 使用Convert()函数将binary数据类型转换成numeric数据类型,为何会出现 下列出错信息?
Msg 8114, Level 16, State 2
Error converting type binary to type numeric.
答: Microsoft SQLServer 6.5无法以Convert()函数将binary数据类型转换成n umeric数据类型,此为"Transact-SQL Reference"手册第189页有误。
问: 如何将char数据类型的数据转成datetime数据类型以便使用dateadd┅等日 期函数,试举一例?
答: 举例如下:建test table,包含t_date,t_time两个栏位,格式分别为”Y YMMDD”及”HHMMSS”。如要将年份加一年,则:
select dateadd(yy,1,convert(datetime,t_date+"
"+substring(t_time,1,2)+":"
+substring(t_time,3,2)+":"+substring(t_time,5,2)))
from test
问:如何移除duplicate的row?
答:基本上SQL Server有许多方式防止duplicate row产生如primary key const raint,trigger,index以及unique constraint,但是在一些状况如数据是由no n-relational database import进来,而import时没有设定为唯一。您可参考下 列将col1,col2相同的row移除的例子。
1.建立table的script:create table t1(col1 int, col2 int, col3 char(50 )) 找出重复的row。
SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*)>1
2.如果重复的数据很少,如只有(col1,col2)=(1,1)重复,并且有三次,则可使 用下列script:
set rowcount 2
delete from t1
where col1=1 and col2=1
3.其中rowcount=重复的次数减一。
4.依步骤2以group by找出重复的数据和次数,如果重复的数据很多,可参考下 列方式:
1) 将重复的数据和次数放入一table,如
holdkey
SELECT col1, col2, count(*)
INTO holdkey
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1
2) 将重复的row和次数放入一table,如
holddups
SELECT DISTINCT t1.*
INTO holddups
FROM t1, holdkey
WHERE t1.col1 = holdkey.col1 AND t1.col2 = holdkey.col2
3) 将重复的row由table删除:
DELETE t1
FROM t1, holdkey
WHERE t1.col1 = holdkey.col1
AND t1.col2 = holdkey.col2
4) 将存在holddups的数据放入原table:
INSERT t1 SELECT * FROM holddups
问: 在Microsoft SQL Server 6.5 中设定某一栏为NotNull后是否有办法再将其 改成允许Null?
答: 必需重建Table。
问: 如果Microsoft SQL Server 6.5在error log出现17824,17832以及1608 等 错误讯息如何处理?
答: 通常这些问题都是因为网路或Client端应用程序引起非SQL Server本身问题 ,请先检查网路问题。
问: 如果将Microsoft SQL Server 6.5 Tempdb in RAM设定太高以致无法启动M icrosoft SQL Server如何处理?
答: 在ISQL/W下执行下列指令:
sqlservr ━c ━f
isql ━Usa ━Ppassword
重新设定tempdb in RAM的大小:
sp_configure ‘tempdb in ram',x
go
reconfigure
go
重新启动Microsoft SQL server。
问:MSDB损毁且无法由备份还原,如何重建MSDB database?
答:请依下列方式重建MSDB,但您必需重建MSDB的tasks、alerts及operators。
启动SQLServer Enterprise Manager。
停止SQLExecutive。
将目前的MSDB删除。
执行\MSSQL\INSTALL\INSTMSDB.SQL。
执行\MSSQL\INSTALL\Servmsgs.sql。
重新启动SQLExecutive。
问: 执行SQL Executive-based tasks失败并有下列讯息如何处理?
Error: 1105, Severity : 17, State 2
Can't allocate space for object '%.*s' in database '%.*s' because the '%.*s' segment is full. If you ran out of space in Syslogs, dump the t ransaction log. Otherwise, use ALTER DATABASE or sp_extendsegment to i ncrease the size of the segment.
答: 发生此种状况因为MSDB database已满,系统管理员可手动删除旧的项目或 参照下列方式建立一个store procedure,再执行此stored procedure:
use master
go
sp_configure 'allow', 1
go
reconfigure with override
go
drop proc sp_cleanbackupRestore_log
go
create proc sp_cleanbackupRestore_log
@DeleteBeforeDate datetime
as
begin
Delete from msdb.dbo.sysbackupdetail where backup_id
in (Select backup_id from msdb.dbo.sysbackuphistory where
backup_start <=
@DeleteBeforeDate)
Delete from msdb.dbo.sysbackuphistory where backup_start <=
@DeleteBeforeDate
Delete from msdb.dbo.sysrestoredetail where restore_id
in (Select restore_id from msdb.dbo.sysrestorehistory where
backup_start <=
@DeleteBeforeDate)
Delete from msdb.dbo.sysRestorehistory where backup_start<=
@DeleteBeforeDate
end
go
sp_configure 'allow', 0
go
reconfigure with override
若要删除 Apr 30,1998之前的项目,则执行exec sp_cleanbackupRestore_log ' 4/30/98'
-- 如果你觉得可笑的话,那么你错了
如果你觉得不可笑的话,那么我错了
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 168.160.66.50]
|
|