Sitecore Databases
Three types databases are available in sitecore
Master
The Master database is the authoring database - it contains all versions of any content or assets.
Core
The Core database is all Sitecore settings, as well as the tables containing the .Net membership provider (i.e. users/roles contained in the Sitecore repository)
Web
The Web database is only the latest published version, and the content that is driving the live web site. Therefore it is a subset of the master database, optimised for size and speed. When content is published, or goes through the publishing task of a workflow, the latest content version is copied from the master to web database.
Of course, in an Enterprise deployment, you may have multiple Sitecore instances, which may share DBs (or not)
With Code
In a Sitecore solution, the term database means something slightly different depending on the the context:
- An actual relational database or other repository used by the Sitecore CMS.
- An abstraction of a relational database or other repository through Sitecore APIs (data providers).
- An actual relational database or other repository used by an optional Sitecore module.
- An actual relational database or other repository used by your solution.
- A set of tables within a relational database used to support data not represented as Sitecore items, such as those used to manage security accounts, roles, and profiles.
A default Sitecore configuration includes three relational databases abstracted as Sitecore databases using the Sitecore.Data.Database class:
- Master: Contains all versions of all content and media in all languages, including items with publishing restrictions.
- Web: The default publishing target database contains only the latest approved version in each language for each item.
- Core: Configures the Sitecore user interfaces.
Developers frequently retrieve items from the context database determined by the httpRequestBegin pipeline, potentially through the Sitecore.Context.Database static property or the Database property of the Sitecore.Data.Items.Item instance exposed by the context item (the Sitecore.Context.Item static property).
For example:
Sitecore.Data.Database database = Sitecore.Context.Database;
Sitecore.Data.Items.Item contextItem = Sitecore.Context.Item;
Sitecore.Diagnostics.Assert.IsNotNull(contextItem, "contextItem");
database = contextItem.Database;
In web controls and potentially in sublayouts or other rendering contexts, you can use the data source item instead of the context item. For example, in a web control:
Sitecore.Data.Items.Item dataSource = this.GetItem();
You can use the static GetDatabase() method of the Sitecore.Configuration.Factory
Class to retrieve a database by name. For example, to retrieve the Master database:
database = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Diagnostics.Assert.IsNotNull(database, "master database");
Once you have a database, you can access its GetItem() method to retrieve an item by passing its path, ID, or other criteria.