The following line works:
SELECT * FROM [myschema].users
But this does not:
SELECT * FROM users
How can you tell the name of the current default schema? SELECT SCHEMA_NAME(); The SCHEMA_NAME() function will return the name of a schema if you pass it the schema_id but if you don't pass anything, it will return the name of the current default schema.
The dbo schema is the default schema of every database. By default, users created with the CREATE USER Transact-SQL command have dbo as their default schema. The dbo schema is owned by the dbo user account.
Set the Default Schema for a Windows Group First you need to map the login to the database by checking the Map column, then click on the Default Schema column to select the schema. In our example, we selected dbo as the default.
To change the schema of a table by using SQL Server Management Studio, in Object Explorer, right-click on the table and then click Design. Press F4 to open the Properties window. In the Schema box, select a new schema. ALTER SCHEMA uses a schema level lock.
A default schema is user-specific:
USE yourDatabase; ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema;
More information about the ALTER TABLE for SQL 2005 might help you as well.
As this is user-specific, if you have multiple users, you will need to execute this query (on each database) for each user whose default schema you want to update.
It is important to note:
The value of DEFAULT_SCHEMA is ignored if the user is a member of the sysadmin fixed server role. All members of the sysadmin fixed server role have a default schema of dbo.
You can use:
ALTER USER Mary51 WITH DEFAULT_SCHEMA = Purchasing;
To set the default schema for user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With