SQL .

SQL Insert

SQL Insert Example One - A Basic Insert

Q: How would we add John Travolta as being in Pulp Fiction to the Thespian_Film_Table table?
   
 Insert Into Thespian_Film_Table (Thespian_Last_Name, 
                                  Thespian_First_Name,
                                  Film_Title)
                         Values ("Travolta", 
                                 "John",
                                 "Pulp Fiction");
Note: The first parenthesis contains the column names in the Thespian_Film_Table. The second parenthesis contain the data to go into the row being inserted. The data being inserted in the second line must be in order corresponding to the column name order in the first line.

SQL Insert Example Two - Inserting Rows From One Table Into Another Table

Q: I have created my own John_Travolta_Film_Table. How can I bring all the rows for John Travolta in the Thespian_Film_Table into my new table?
   
 Insert Into John_Travolta_Film_Table (Thespian_Last_Name,
                                       Thespian_First_Name,
                                       Film_Title)
 Select Thespian_Last_Name, 
        Thespian_First_Name, 
        Film_Title
   From Thespian_Film_Table
  Where Thespian_Last_Name = "Travolta"
    and Thespian_First_Name = "John";
Note: Just as in example number one, the column names being inserted into must be in the same order as the column names being selected from.
Special Thanks: to Tomislav for catching a dyslexic typo on this page.
Comments
Sign in to be the first to comment on SQL Insert.