Search code examples
.netsql-serverentity-frameworkef-code-firstdbo

Should I let EF CF create my tables with the user "dbo"?


I am just starting out with SQL Server and I let Entity Framework code first create my data tables. Here's the SQL for one of the tables:

CREATE TABLE [dbo].[UserProfile] (
    [UserId]   INT            IDENTITY (1, 1) NOT NULL,
    [UserName] NVARCHAR (MAX) NULL,
    PRIMARY KEY CLUSTERED ([UserId] ASC)
);

I notice "dbo" but I am not sure what this means. Is this similar to the data being stored in the master database? Now I would like to manually drop / create tables instead of letting EF do this.

Can someone tell me if there is a better way for me to create the tables. Should I for instance create them with something other than dbo? Also can I create multiple databases within my SQL Server and then place my tables there?


Solution

  • dbo stands for 'database owner'. It is simply the default schema in SQL Server. EF Code first uses the dbo schema by default. If you want to overide, see:

    How can I stop Entity Framework 5 migrations adding dbo. into key names?

    [Schemas are used to group objects. For instance, a Report schema might contain read-only views used for reporting.]