Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Server setting that changes schema from dbo

Is there an option/setting/default in SQL Server that causes new stored procedures to be placed under your userid instead of schema dbo? I am in the db-owner group, as tested by this script.

For example, I run this in SSMS:

create proc TestName as 
   print 'this is just a test' 

The stored procedure created is CORP\myuser.TestName, so CORP\myuser seems to be the schema, right?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Or do I need to specifically specify dbo.TestName when I create it?

Relates to this question: Alter Schema Transfer fails even when I'm a db-owner

>Solution :

The stored procedure created is CORP\myuser.TestName, so CORP\myuser seems to be the schema, right?

Yes, I suspect that is your default schema.

How do I set the schema?

On the object, you say CREATE PROCEDURE dbo.TestName or CREATE PROCEDURE desired_schema_name.TestName. That you haven’t had to do this before has been blind luck that nobody writing the code has had a different default schema. But there are other reasons to not be lazy, too: see Bad habits: Avoiding the schema prefix.

On your user, you say:

ALTER USER [CORP\myuser] WITH DEFAULT_SCHEMA = dbo;

But this may have to be run by someone with more privileges, and it may be the case that you don’t even have the permissions to create a procedure in the dbo schema (or transfer objects there).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading