Wednesday, January 19, 2011

Inserting Records

In this post, I will focus on inserting records into the tables made during the I Break Code's Creating Tables post. During we created two tables Authors and Books. The Authors table has three columns: author_ID, first_Name; last_Name. The Books table has five columns: book_ID, title, genre; description.

We are going to insert two records into our authors table:

Author 1:
First name: Geoffrey
Last name: Chaucer

Author 2:
First name: William
Last Name: Shakespeare

  1. USE Library;
  2. GO
  3. INSERT INTO Authors
  4. (
  5.     first_Name
  6.     , last_Name
  7. )
  8. VALUES
  9. (
  10.     ' Geoffrey'
  11.     , 'Chaucer'
  12. );
  13. INSERT INTO Authors
  14. (
  15.     first_Name
  16.     , last_Name
  17. )
  18. VALUES
  19. (
  20.     ' William'
  21.     , 'Shakespeare'
  22. );

When executed, this query will insert two authors into our "Authors" table with the provided information.

Now, let's add some books to our "Books" table.

Book 1:
Title: The Cantebury Tales
Genre: Classic/Poetry
Description: A great collection of poems and stories.

Book 2:
Title: Macbeth
Genre: Classic/Play
Description: "Fair is foul, and foul is fair". - ( Quote Act I, Scene I).

  1. USE Library;
  2. GO
  3. INSERT INTO Books
  4. (
  5.     title
  6.     , genre
  7.     , [description]
  8. )
  9. VALUES
  10. (
  11.     'The Cantebury Tales'
  12.     , 'Classic/Poetry'
  13.     , 'A great collection of poems and stories.'
  14. );
  15. INSERT INTO Books
  16. (
  17.     title
  18.     , genre
  19.     , [description]
  20. )
  21. VALUES
  22. (
  23.     'Macbeth'
  24.     , 'Classic/Play'
  25.     , '"Fair is foul, and foul is fair". - ( Quote Act I, Scene I).'
  26. );


When executed, this query will insert two books into our "Books" table with the provided information.

No comments:

Post a Comment

I Break Code Where code gets done.
ASP.NET | HTML | SQL Server | VB.NET | Request A Topic |