Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

User Default Schema Problem Expand / Collapse
Author
Message
Posted Monday, January 11, 2010 3:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, June 02, 2012 1:05 AM
Points: 38, Visits: 69
I did the following:
1- create database d1.
2- create new user u1
3- create a schema s1 for u1.
4- set s1 as default schema for u1.
5- create new login login1.
6- map the login to database d1 using user u1 with default schema s1.


i write a statement to create a new table (without specifying the schema as a prefix), the table was created in the dbo schema instead of the s1 (the default schema).

i modified the statement to include the s1.tablename, and the table was created successfully in the s1 schema.

When writing a select statement to get data from the the table without specifying the schema, the data has been retrieved from the s1 table (the default schema table), which is the expected result.


So why the table was created in dbo schema instead of the default schema?
Post #845273
Posted Monday, January 11, 2010 4:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:25 AM
Points: 6,861, Visits: 8,045
/* 1- create database d1;*/
create database d1;

/* 5- create new login login1. */
CREATE LOGIN [Login1] WITH PASSWORD=N'Login&', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

/* 2- create new user u1 */
USE [d1]
CREATE USER [u1] FOR LOGIN [Login1] ;
EXEC sp_addrolemember N'db_owner', N'u1'
GO


/* 3- create a schema s1 for u1. */
create schema s1;
go

/* 4- set s1 as default schema for u1. */
ALTER USER [u1] WITH DEFAULT_SCHEMA=[s1] ;
go

/* 6- map the login to database d1 using user u1 with default schema s1. */
-- already mapped by step 2

/* 7 */
-- Switch to user ( I need to be sysadmin !!)
Execute as login='Login1'
Create table Mytable (col1 int not null);

-- switch back to myself
revert;

Select *
from information_schema.tables
where table_name = 'Mytable'

/*
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
d1 s1 Mytable BASE TABLE
*/

Print 'No problem'

/* Clean up
use master

drop database d1 ;
drop login Login1;
*/



Johan

     Jul 13  

Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #845285
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse