2

In my local or on a dedicated server, when i create a table i see the table name as follows:

dbo.Foo

As i was given a database account from some plesk environment, the tables which were created get the name :

mydbuser.Foo

How does prefix matter for my code? or If i create a table/ restore one from my backup, should i expect weird results?

DarthVader
  • 52,984
  • 76
  • 209
  • 300

2 Answers2

2

dbo is the default schema that is assigned to a table when you create a table and don't assign a schema explicitly. A database schema is a way to logically group objects such as tables, views, stored procedures etc. You can read more about schemas here

How does prefix matter for my code?

If you don't specify schema in the code, then it will take dbo as default. Though if you have a table with schema other than dbo, then you will have to specify in your code as well, otherwise it won't execute.

If i create a table/ restore one from my backup, should i expect weird results?

Schemas are not evil. If you specify them correctly, everything should be fine.

Pang
  • 9,564
  • 146
  • 81
  • 122
Ehsan
  • 31,833
  • 6
  • 56
  • 65
0

dbo

It is schema. If no default schema is defined for a user account, SQL Server will assume dbo is the default schema.

As per MSDN

SQL Server 2005 introduced the concept of database schemas and the separation between database objects and ownership by users. An object owned by a database user is no longer tied to that user. The object now belongs to a schema – a container that can hold many database objects. The schema owner may own one or many schemas. This concept creates opportunities to expose database objects within a database for consumption yet protect them from modification, direct access using poor query techniques, or removal by users other than the owner.

To create your own Schema, you can use following script:

CREATE SCHEMA [EnterSchemaNameHere] AUTHORIZATION [dbo]

You can use them to logically group your tables, for example by creating a schama for "Financial" information and another for "Personal" data. Your tables would then display as:

Financial.Foo

Personal.Foo

Community
  • 1
  • 1
Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43