How to Create or Replace a View SQL Server in Microsoft

How to Create or Replace a View SQL Server in Microsoft thumbnail
Views are SQL Server statements.

Views are pre-configured SQL statements that return a large set of data. The statements used to create a view are similar to those used to create tables. A SQL programmer can retrieve only part of the data from a view and filter results. You can create a new view and delete the old one in SQL server. To create a view, the programmer simply uses the "create" statement. To delete a view, the programmer uses the "drop" statement. This replaces a view on your SQL server.

Instructions

    • 1

      Open your SQL Management Studio application and log into the database using the "sa" user name and password. Creation of views, tables and queries require higher access privileges, so the sa user name and password are used.

    • 2

      Create a view using the command console. The following is an example of a view created to retrieve a list of customers and their orders:
      create view myView
      as
      select * from customer c join orders o on c.customerId=o.customerId
      Press F5 to execute the statement. The view is created and displayed in the "View" section for your database server.

    • 3

      Drop the old view. The "drop" statement is used to delete queries, tables and views. The following code deletes the old view for replacement:
      drop view myOldView
      Press F5 to execute the statement.

    • 4

      Right-click the newly created view in the list of objects for the database on the left side of your SQL Management Studio application. Select "Rename" from the menu. Give the new view the same name as the view you want to replace. The old view is now replaced.

Tips & Warnings

  • Ensure you want to delete a view when using the "Drop" statement. The drop statement permanently deletes the code.

Related Searches:

References

  • Photo Credit database on paper image by .shock from Fotolia.com

Comments

You May Also Like

Related Ads

Featured