creating view in sqlserver creating view in sqlserver database database

creating view in sqlserver


Your view is using ANSI 92 syntax. While this will work for older database versions, it will not work in SQL Server 2012. See Mike Walsh's blog on this topic.

1 - When using SSMS views do not show up right away. Right click and hit refresh.

2 - It is very important to make sure you are in the correct database. I am sure many people, including me, have create an object or two in master. This is the default for a new login.

This can be changed by changing the default database for your login.

3 - Execute the USE command to change the database context (default).

The snippet below is a SQL Server 2012 compliant version.

USE [hed2]GOcreate view v_news asSELECT [n_id]  ,[n_title]  ,[n_detail]  ,[n_date]  ,[n_sdate]  ,[n_edate]  ,[n_admin]  ,[a_name]  ,[a_email]  ,[a_role]  ,[a_status]FROM dbo.hed_news JOIN dbo.hed_admins ON hed_news.n_admin = hed_admins.a_idGO


Three things:

  1. You must use JOINS and the way your query is written is bad. Just an observation. Nothing to do with your question.
  2. Did you try running SELECT * FROM v_news? That would return results.
  3. Right click and views in SSMS and select refresh. It will show up in the list

Raj