Primary Key Foreign Key

Primary Key

  • Uniquely identifies each row.
  • A table can have only one primary key, but it may consist of multiple columns (composite key).

    Foreign Key

    • Ensures referential integrity by linking two tables.
      CREATE TABLE Orders (
         OrderID INT PRIMARY KEY,
         CustomerID INT,
         FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
      );
      

      Comments

      Leave a Reply

      Your email address will not be published. Required fields are marked *