The Link database saves all links between Sitecore items across the databases (core, master, web) and across the language versions. This database helps to find out not only the list of items, which the specific item refers to but also the items which refer this item.
For example, a page created from a specific template contains a reference to that template and vice versa.
In content editor, this database is used in “Navigate -> Links“.
or when u delete an item, it asks what you should do with the existing links to the item to be deleted -
The link database is primarily a table (dbo.Links) within our core db configured as -
<
LinkDatabase
type
=
"Sitecore.Data.$(database).$(database)LinkDatabase, Sitecore.Kernel"
>
<
param
connectionStringName
=
"core"
/>
</
LinkDatabase
>
Link db gets updated on following events -
- item:saved
- item:deleted
- item:copied
- item:versionRemoved
Link db can be rebuilt as -
Same can be done programmatically as -
var
dbName =
"master"
;
var
db = Factory.GetDatabase(dbName);
Globals.LinkDatabase.Rebuild(db);
Rebuilding the link db can be time consuming if there is large amount of content in Sitecore. It is preferable to update links to a specific item when needed. This can be done programmatically as -
var
db = Factory.GetDatabase("master");
var
item = db.GetItem(
"/sitecore/content/Home"
);
Globals.LinkDatabase.UpdateReferences(item)
Developers can get the list of items that refer a particular item using below code-
var
db = Factory.GetDatabase("master");
var
item = db.GetItem(
"/sitecore/content/Home"
);
ItemLink[] links = Globals.LinkDatabase.GetReferrers(item);