Reputation: 32808
I am using the New Query window in Visual Studio 2012 Server Explorer. Here is the script I am trying to execute:
ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT fk_UserId;
ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT fk_RoleId;
DROP TABLE [dbo].[ExtraUserInformation];
DROP TABLE [dbo].[UserProfile];
DROP TABLE [dbo].[webpages_Membership];
DROP TABLE [dbo].[webpages_OAuthMembership];
DROP TABLE [dbo].[webpages_Roles];
DROP TABLE [dbo].[webpages_UsersInRoles];
CREATE TABLE [dbo].[ExtraUserInformation] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[UserId] INT NOT NULL,
[FullName] NVARCHAR (MAX) NULL,
[Link] NVARCHAR (MAX) NULL,
[Verified] BIT NULL,
CONSTRAINT [PK_dbo.ExtraUserInformation] PRIMARY KEY CLUSTERED ([Id] ASC)
);
There is currently no webpages_UsersInRoles table and it gives me an error message saying:
Msg 4902, Level 16, State 1, Line 5
Cannot find the object "dbo.webpages_UsersInRoles" because it does not exist or you do not have permissions.
After this message the script seems to stop and it fails to create the other tables after this. Is there away that I can make the script continue after it passed the expected error?
Upvotes: 1
Views: 2187
Reputation: 1740
There are a few options here, its really a matter of what you think is right for your script.
Upvotes: 1
Reputation: 30628
Better than continuing past the error is to test for the failure condition in the script, for example only dropping a table if it exists.
Instead of:
DROP TABLE [dbo].[webpages_UsersInRoles];
try:
IF OBJECT_ID('dbo.webpages_UsersInRoles', 'U') IS NOT NULL
DROP TABLE dbo.webpages_UsersInRoles
(from https://stackoverflow.com/a/7887033/163495)
Upvotes: 1