none
SQL Error Msg 208, Level 16, State 1, Line 1

    Question

  • I am attempting to execute the following query "select * from master GO" in MS SQL Server Management Studio Express  on MS SQL Server 2005 with the following error message "Msg 208, Level 16, State 1, Line 1 Invalid object name 'master'.". Note I can see the database in the objects explorer pane.  Also this is a new install and my first experience with the tool and SQL on a PC.  What am I missing format, path, security ? 
    Tuesday, February 17, 2009 6:34 PM

All replies

  • SELECT * FROM _________

    Needs to reference a table or view - not a database.  The database contains tables and views.

    Try this:
    USE master  
    GO  
    SELECT * FROM INFORMATION_SCHEMA.COLUMNS  
     

    (note that you don't need to switch to master to query information_schema.columns - I just did it to tie in with your example).

    Does this help?


    Aaron Alton | thehobt.blogspot.com
    Wednesday, February 18, 2009 5:46 AM
    Moderator
  • Master is the name of the database (system db). You need to query the objects like tables or views etc.

    Select * from tablename
    Select * from viewname

    Consider the below query where i create a new table named Employee in master database.

    USE master
    GO
    CREATE table Employee
    (
    Empid int,
    Empname varchar(30)
    )
    GO
    INSERT INTO Employee VALUES(1,'John')
    INSERT INTO Employee VALUES(2,'Tom')
    INSERT INTO Employee VALUES(3,'Mike')
    GO

    --I am querying the table from within the master database
    Use master
    Select * from Employee

    --I can also query it by specifying the dbname.schemaname.objectname as follows
    Select * from master.dbo.Employee

    --The below is the 4 part naming convention of using the servername.dbname.schemaname.Objectname
    Select * from [PC0032\SQLEXPRESS].master.dbo.Employee

    where dbo=is the default schema name.

    -Deepak

    Deepak | Mark the answers if it helps to solve your problem |
    Wednesday, February 18, 2009 5:56 AM
    Moderator