({{, (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[(RefLink[File, paclet:ref/File])["filename"]] 
represents a reference to a local file-based SQL database.}, {, (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[(RefLink[URL, paclet:ref/URL])["url"]]
represents a reference to a server-based SQL database.}, {, (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[assoc]
represents a fully specified reference to any SQL database.}})

OpenersNotesSection(Spacer1)Details

(RefLink[DatabaseReference, paclet:ref/DatabaseReference])[…] includes information on how to connect to a database, but does not actually perform the connection. The connection is automatically performed by functions like (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]), as well as by database querying functions such (RefLink[EntityValue, paclet:ref/EntityValue]).

In (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[(RefLink[URL, paclet:ref/URL])["url"]], "url" is typically of the form "backend://user:password@host:port/name".

In (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[assoc], typical elements of assoc include:

Possible values for "Backend" include "SQLite", "PostgreSQL", "MySQL", "MicrosoftSQL", "Oracle".

For file-based databases such as SQLite, "Name" gives the path to the file containing the database.

For server-based databases, "Name" gives the name of the database at the specified endpoint.

For file-based databases, no values need to be specified for "Host" and "Port".

For server-based databases, "Host" can be a network host name or an IP address, specified with a string or using an (RefLink[IPAddress, paclet:ref/IPAddress]) object.

If no value for "Port" is specified, a default for each type of backend will be used.

(RefLink[DatabaseReference, paclet:ref/DatabaseReference])[…][prop] gives information about the database being referenced.

The property prop can be any of the elements that can be supplied in (RefLink[DatabaseReference, paclet:ref/DatabaseReference])[assoc], as well as:

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Construct a (RefLink[DatabaseReference, paclet:ref/DatabaseReference]) from a file:

DatabaseReference[File["database.sqlite"]]

Construct a (RefLink[DatabaseReference, paclet:ref/DatabaseReference]) from a (RefLink[URL, paclet:ref/URL]):

DatabaseReference["postgres://user:pass@localhost:1000/database"]

Construct a (RefLink[DatabaseReference, paclet:ref/DatabaseReference]) from an (RefLink[Association, paclet:ref/Association]):

DatabaseReference[<|"Backend" -> "postgres", "Host" -> "localhost", "Port" -> 1000, "Name"->"database", "Username" -> "user", "Password" -> "pass"|>]

OpenersExampleSection1(Spacer1)Scope  (1)

Extract properties from a (RefLink[DatabaseReference, paclet:ref/DatabaseReference]):

ref=DatabaseReference["postgres://user:pass@localhost:1000/database"]

ref["Username"]

Multiple properties can be extracted at once:

ref[{"Username", "Password"}]

OpenersExampleSection3(Spacer1)Applications  (1)

Use in conjunction with (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) to extract the schema of a database:

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

Construct an (RefLink[EntityStore, paclet:ref/EntityStore]) from the (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) object:

store = EntityStore[schema]

EntityRegister[store]

Perform a query:

EntityValue["offices", "city"]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Construct a (RefLink[DatabaseReference, paclet:ref/DatabaseReference]) pointing to a file:

file=DatabaseReference[File[FindFile["ExampleData/ecommerce-database.sqlite"]]]

Connect manually to the database:

DatabaseConnect[file]

And disconnect:

DatabaseDisconnect[file]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

A (RefLink[DatabaseReference, paclet:ref/DatabaseReference]) does not guarantee the existence of the database:

DatabaseConnect[DatabaseReference["postgres://user:pass@localhost:1000/database"]]

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Working with Information in Relational Databases, paclet:guide/WorkingWithRelationalDatabases])}})}})