Page 50 - SQL
P. 50

LastName VARCHAR(20) NOT NULL,
             PhoneNumber VARCHAR(10) NOT NULL,
             CityID INT FOREIGN KEY REFERENCES Cities(CityID)
         );


        Here could you find a database diagram.


























        The column CityID of table Employees will reference to the column CityID of table Cities. Below you
        could find the syntax to make this.


         CityID INT FOREIGN KEY REFERENCES Cities(CityID)


          Value            Meaning


          CityID           Name of the column

          int              type of the column


          FOREIGN KEY      Makes the foreign key (optional)


          REFERENCES       Makes the reference
          Cities(CityID)   to the table Cities column CityID


        Important: You couldn't make a reference to a table that not exists in the database. Be source to
        make first the table Cities and second the table Employees. If you do it vise versa, it will throw an
        error.


        Create a Temporary or In-Memory Table


        PostgreSQL and SQLite




        To create a temporary table local to the session:


         CREATE TEMP TABLE MyTable(...);




        https://riptutorial.com/                                                                               32
   45   46   47   48   49   50   51   52   53   54   55