skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search