1

I got 3 tables on my sql database

PL01_PROJECT
DE06_PROJECT
LT01_PROJECT

All tables have the same columns header and number

I want to create a view where is appending all table 1by 1 so to have a vie with all data from the tables I tried the following code

I searched for a solution here but looks like do not find the table but table name are exactly as I wrote, I USE query by MICROSOFT SQL SERVER MANAGEMENT STUDIO, how possible do not find table ?

CREATE VIEW TEST
AS

SELECT *  FROM dbo.PL01_PROJECT
UNION ALL
SELECT * FROM dbo.LT01_PROJECT
UNION ALL
SELECT * FROM dbo.DE06_PROJECT

GO

Msg 208, Level 16, State 1, Procedure TEST, Line 4 [Batch Start Line 0] Invalid object name 'dbo.PL01_PROJECT'.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Matt
  • 9
  • 2
  • 1
    If the table doesn't exist, you cannot create a view using it. – Gordon Linoff Sep 12 '19 at 13:54
  • First make sure your query is being executed against the right database by putting a USE [DBName]; GO before your CREATE VIEW statement. If that doesn't fix it, then test to make sure you can read the table by highlighting the SELECT * FROM dbo.PL01_PROJECT and hitting F5 – Robert Sheahan Sep 12 '19 at 14:03
  • And for heavens sake stop using select *. Especially in a view. – Sean Lange Sep 12 '19 at 14:17
  • 2
    Often when you see multiple tables with the exact same schema like this it is an indication that the database design is not ideal. Instead of multiple columns you should add one more column to your table to hold the project name. The way this seems to be going is you are creating a new table for every project. This means everytime you add a new project to your system you have to add a new table and subsequently update every query that touches them. – Sean Lange Sep 12 '19 at 14:21
  • Are you sure your tables exist in dbo schema? – Faisal Mehboob Sep 12 '19 at 15:47

0 Answers0