Begin Try/Catch Question/Problem  
Author Message
Sanford





PostPosted: Top

SQL Server >> Begin Try/Catch Question/Problem

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C75416.729BB810
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am executing the T-SQL statement shown below in Management Studio (SQL =
Server 2005). When I execute this, an error should occur because a =
clustered index already exists on the table. What I don't understand is =
why I am seeing the error in M.S. because I've wrapped this in a Begin =
Try / Begin Catch.

Here is the T-SQL:

Begin Try
ALTER TABLE [dbo].[ProjectRevenueRecognition_UDF] ADD CONSTRAINT =
[PK_ProjectRevenueRecognition_UDF] PRIMARY KEY CLUSTERED ([RowID])|
End Try
Begin Catch
End Catch

The error displayed by M.S is:

Msg 1779, Level 16, State 0, Line 2
Table 'ProjectRevenueRecognition_UDF' already has a primary key defined =
on it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.

BOL says that any error below Level 20 should be handled by the Begin =
Try.=20

Thanks for you help on this.

------=_NextPart_000_0006_01C75416.729BB810
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2963" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I am executing the T-SQL statement =
shown below in=20
Management Studio (SQL Server 2005). When I execute this, an error =
should occur=20
because a clustered index already exists on the table. What I don't =
understand=20
is why I am seeing the error in M.S. because I've wrapped this in a =
Begin Try /=20
Begin Catch.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is the T-SQL:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Begin Try<BR>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
ALTER TABLE [dbo].[ProjectRevenueRecognition_UDF] ADD CONSTRAINT=20
[PK_ProjectRevenueRecognition_UDF] PRIMARY KEY CLUSTERED =
([RowID])|<BR>End=20
Try<BR>Begin Catch<BR>End Catch</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<DIV><FONT face=3DArial size=3D2>The error displayed by M.S =
is:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Msg 1779, Level 16, State 0, Line =
2<BR>Table=20
'ProjectRevenueRecognition_UDF' already has a primary key defined on =
it.<BR>Msg=20
1750, Level 16, State 0, Line 2<BR>Could not create constraint. See =
previous=20
errors.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT size=3D2>
<DIV><FONT face=3DArial size=3D2>BOL says that any error below Level 20 =
should be=20
handled by the Begin Try. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for you help on =
this.</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV></FONT></FONT></DIV></DIV></BODY></HTML>

------=_NextPart_000_0006_01C75416.729BB810--

SQL Server122