user3545833
user3545833

Reputation: 99

SQL server Invalid Column name Invalid object name

I'm having a problem with a table I created. I am trying to run a query however a red line appears under my code ('excursionID', and 'excursions'), claiming 'Invalid Column name 'excursionID' and 'Invalid object name 'dbo.excursions' even though I have created the table already!

Here is the query

    SELECT 
        excursionID

    FROM [dbo].[excursions]

Here is the query I used to create the table

    USE [zachtravelagency]
    CREATE TABLE excursions (
        [excursionID] INTEGER NOT NULL IDENTITY (1,1) PRIMARY KEY, 
        [companyName] NVARCHAR (30) NOT NULL,
        [location] NVARCHAR (30) NOT NULL,
        [description] NVARCHAR (30) NOT NULL,
        [date] DATE NOT NULL,
        [totalCost] DECIMAL NOT NULL,

I've tried dropping the table and inserting table again.

For some reason all my other tables work, it's just this table that doesn't identify itself. I'm very new to SQL so thank you for your patience!

Upvotes: 0

Views: 1234

Answers (1)

Andrey Ganin
Andrey Ganin

Reputation: 359

You use DB [zachtravelagency] for create table.And You dont use this DB in your query. Default used db master in SSMS. Try

SELECT 
    excursionID

FROM [zachtravelagency].[excursions]

Upvotes: 1

Related Questions