({{, (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]
represents schema information about a relational database.}, {, (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[db]
gives the complete schema of the database referenced by db.}, {, (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[{(Subscript[table, 1]) (Subscript[table, 2]),…},db]
gives schema information related to the tables (Subscript[table, i]).}})

OpenersNotesSection(Spacer1)Details and Options

In (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[db] or (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[tables,db], the database can be specified using (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[…], (RefLink[URL, paclet:ref/URL])[…] or (RefLink[File, paclet:ref/File])[…].

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["prop"] can be used to access database-level properties. These include:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table",prop] can be used to access table-level properties. These include:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table","PrimaryKey",prop] can be used to access the properties of the primary key:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table","ForeignKeys"] gives a list of associations with the following elements:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table","Indexes"] gives a list of associations that include the following elements:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table","UniquenessConstraints"] gives a list of associations with the following elements:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase])[…]["table","column",prop] can be used to access column-level properties. These include:

(RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) has the following option:

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Construct a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) object:

schema=RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]

Find out what tables are present in the database:

schema["Tables"]

Construct a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) with a subset of the tables:

schema=RelationalDatabase[{"productlines"},FindFile["ExampleData/ecommerce-database.sqlite"]]

OpenersExampleSection1(Spacer1)Scope  (1)

Construct a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) object:

schema=RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]

Extract schema information:

schema["Tables"]

Extract information about a table:

schema["offices", "PrimaryKey"]

Extract information about a column:

schema["offices", "city", "Nullable"]

Available properties at each level:

schema["Properties"]

schema["offices", "Properties"]

schema["offices", "city", "Properties"]

OpenersExampleSection3(Spacer1)Applications  (1)

Construct a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) object:

schema=RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]

Construct an (RefLink[EntityStore, paclet:ref/EntityStore]) from it:

store = EntityStore[schema]

Register the (RefLink[EntityStore, paclet:ref/EntityStore]):

EntityRegister[store]

Perform a query:

EntityValue["offices", "city"]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Visualize the structure of the foreign keys of a database:

rdb=RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]

Graph[Join@@(Thread[#->rdb[#, "ForeignKeys", "ToTable"]]&/@rdb["Tables"]), VertexLabels -> "Name"]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

Manually editing a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) might result in an object that doesn't reflect the state of the database. For this reason, it's currently not allowed:

ReplacePart[RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]],{1,1,1} -> "foo"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EntityStore, paclet:ref/EntityStore])  ▪  (RefLink[DatabaseReference, paclet:ref/DatabaseReference])  ▪  (RefLink[DatabaseConnect, paclet:ref/DatabaseConnect])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Database Connectivity, paclet:guide/DatabaseConnectivity])}, {▪(RefLinkPlain[Knowledge Representation & Access, paclet:guide/KnowledgeRepresentationAndAccess])}, {▪(RefLinkPlain[Working with Information in Relational Databases, paclet:guide/WorkingWithRelationalDatabases])}})}})