Thursday, March 22, 2012

Check If View Exists

I'm working on a project for my class. I have to test for the existance of a certain view, and if it exists I have to delete it before recreating it. I figure it involves an IF command, and I know how to create a view. Everything in between is a blank for me. Any help would be appreciated. Thanks in advance.

An easy way to do this is to use the INFORMATION SCHEMA objects. They provide a handy way to get at the tables/views/etc inside the database..

Code Snippet

USE MyDatabase;

SELECT * FROM INFORMATION_SCHEMA.VIEWS

If you need to look for anything else inside the database, there are a bunch of others:

http://msdn2.microsoft.com/en-us/library/ms186778.aspx

|||I really appreciate that. Thank you.

No comments:

Post a Comment