Shaul Dar
Shaul Dar

Reputation: 901

In SQL Server (2012), when can I just use a table name "Foo" w/o the full qualification dbname.dbo.Foo?

Is there a setting in the management studio that would allow me, when I create a new query, to use just:

SELECT * FROM Foo

instead of

SELECT * FROM dbname.dbo.Foo

assuming of course there is no ambiguity?

Currently I get an error message. Thanks.

Upvotes: 0

Views: 144

Answers (2)

M.Ali
M.Ali

Reputation: 69524

enter image description here

SELECT YOUR DATABASE NAME HERE FROM THE DROP DOWN LIST and then if there is any ambiguity in column names just use two part name i.e TABLENAME.ColumnName
WHere you open a new query window it opens it in Master database context, And people who has been working with sql server for years and years makes this mistake quite often of openning a query window and start executing a script in master db. so your not the only one :)

You can also use the USE statement i.e

USE DataBase_Name
GO

//your query.........

Upvotes: 0

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11599

You can set a default schema for a User in SQL Server 2012.

Here is the MSDN page

Note: You can't change the schema after setting it once.

Upvotes: 1

Related Questions