- 
                Notifications
    You must be signed in to change notification settings 
- Fork 689
Foreign Key
        Mathias Rangel Wulff edited this page Jun 12, 2015 
        ·
        4 revisions
      
    AlaSQL supports FOREIGN KEY concept.
Syntax:
    CREATE TABLE tableid (
        columnid type REFERENCES reftableid (refcolumnid,...)
    );In this example field Orders.fruitid reference to Fruits table:
     CREATE DATABASE Fruits;
      USE DATABASE Fruits;
      CREATE TABLE Fruits (
        fruitid INT PRIMARY KEY,
        fruitname NVARCHAR(MAX),
        price MONEY
      );
      CREATE TABLE Orders (
        orderid INT PRIMARY KEY IDENTITY,
        fruitid INT REFERENCES Fruits(fruitid),
        qty FLOAT
      );See also: [PRIMARY KEY](Primary Key)
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo