Choose your database:
AnySQL
MySQL
MS SQL Server
PostgreSQL
SQLite
Firebird
Oracle
SQL Anywhere
DB2
MaxDB

Subscribe to our news:
Partners
Testimonials
Ephraim Stevens : "I just wanted to re-iterate what a wonderful job your developers have done and what a wonderful product SQLite Maestro is. There are so many great things to say about it that I won't go into here. It saves an end user a lot of time on repetitive tasks. Keep up the excellent work over there".
Mario Figueiredo: "I can safely forget all I know about SQL when using SQLite Maestro. It is that easy and intuitive to use. It is also nicely drawn with an easy and appealing interface that makes the sometimes boring tasks of database maintenance and administration more endurable.
The decision to support the non-commercial use of your software with a lower price is absolutely worth mentioning. For that alone, I thank you. For everything else, I say keep up the good work".

More

Add your opinion

SQLite Maestro online Help

Prev Return to chapter overview Next

Foreign Keys

A foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table. In other words, a foreign key is a column or a combination of columns that is used to establish and enforce a link between the data in two tables.

 

 

Foreign keys are created within the Foreign Key Properties dialog window. In order to open the dialog you should either

 

open the table in Table Editor and the Foreign Keys tab there;
press the Insert key or select the Add New Foreign Key... item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar)

or

select the table in the explorer tree and use the Create New Foreign Key popup menu item

or

select the table Foreign Keys node or any foreign key within the table in the explorer tree and use the Add New Foreign Key... popup menu item.

 

 

 

Foreign Keys are edited within the Foreign Key Properties dialog window. In order to open the dialog you should either

 

open the table in Table Editor and the Foreign Keys tab there;
press the Enter key or select the Edit Foreign Key item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar)

or

select the foreign key to edit in the explorer tree and use the Edit Foreign Key popup menu item.

       

You can change the name of the foreign key using the Rename Foreign Key dialog. To open the dialog you should either

 

select the foreign key to rename in the explorer tree;
select the Rename Foreign Key item from the popup menu

or

open the table in Table Editor and the Foreign Keys tab there;
select the foreign key to rename;
select the Rename Foreign Key item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar).

 

 

 

To drop the foreign key:

 

select the foreign key to drop in the explorer tree;
select the Drop Foreign Key item from the popup menu

or

open the table in Table Editor and the Foreign Keys tab there;
press the Delete key or select the Drop Foreign Key item from the popup menu (alternatively, you may use the corresponding link of the Navigation Bar)

 

and confirm dropping in the dialog window.

 

 

Select Columns from the Available Fields list to include into the foreign key, select the Foreign Table Name from the drop-down list and its fields from the list to include, and apply the changes by clicking the OK button.

 

 

All the fields which are included into the Foreign Key must be included into indexes as well. See Indexes for details.

 

 

SQLite Maestro allows you to enforce foreign key constraints using referential integrity triggers. To generate such triggers to a foreign key, use the Generate referential integrity triggers link of the foreign key node' popup menu at the Explorer tree. This command is provided to generate 4 triggers: 2 triggers will accomplish the referential integrity in the parent table (on update and on delete) and 2 triggers - on the child one (on insert and on update). Use the opened window to specify the triggers names and set foreign key Cascade options.

 



Prev Return to chapter overview Next