Beginning SQL
Beginning SQL Beginning SQL
Chapter 2 42 CategoryId Category 1 Thriller To check whether it worked, either use your RDBMS’s management tools to view table data or use the following SQL statement: SELECT * FROM Category This statement displays all the records in the Category table. Chapter 3 covers the full details of the SELECT statement. For now, just use it to ensure that the INSERT INTO statement worked. Once you make sure the first INSERT statement works, you can insert more values into your Category table: INSERT INTO Category (CategoryId, Category) VALUES (2, ‘Romance’); INSERT INTO Category (CategoryId, Category) VALUES (3, ‘Horror’); INSERT INTO Category (CategoryId, Category) VALUES (4, ‘War’); INSERT INTO Category (CategoryId, Category) VALUES (5, ‘Sci-fi’); Now your Category table should contain the following values: CategoryId Category 1 Thriller 2 Romance 3 Horror 4 War 5 Sci-fi Check whether yours does by using the following SELECT statement: SELECT * FROM Category You can specify the column names in any order you like, so you could also write the above SQL as follows: INSERT INTO Category (Category, CategoryId) VALUES (‘Historical’, 6); Regardless of category order, SQL performs exactly the same way, as long as you match column names in the first set of brackets with the correct data in the second set. If you want to, you can leave off the column names altogether. You can write the code: INSERT INTO Category (CategoryId, Category) VALUES (6, ‘Historical’)
- Page 74: A keyword is a word that has some m
- Page 78: Introduction to SQL A perfectly val
- Page 82: Data Type Description Storage Used
- Page 86: The char and varchar data types use
- Page 90: Most RDBMSs handle the most common
- Page 94: To add a new column, use the basic
- Page 98: Now that you know what you want to
- Page 102: ❑ Meeting date 2 ❑ Location 2
- Page 106: Generally speaking, picking a data
- Page 110: example, the MemberId field links t
- Page 114: Depending on which RDBMS you’re u
- Page 118: The FilmCategory table is very smal
- Page 122: 2 Entering Information The last cha
- Page 128: Chapter 2 44 Member First Last Date
- Page 132: Chapter 2 46 Now Steve’s record l
- Page 136: Chapter 2 This would work fine with
- Page 140: Chapter 2 If you want to delete all
- Page 146: 3 Extracting Information So far you
- Page 150: Returning Only Distinct Rows If you
- Page 154: The good news is that everything yo
- Page 158: MemberDetails (MemberId, FirstName,
- Page 162: MemberDetails table, the columns Fi
- Page 166: State DateOfJoining New State 2005-
- Page 170: It simply tells the database system
Chapter 2<br />
42<br />
CategoryId Category<br />
1 Thriller<br />
To check whether it worked, either use your RDBMS’s management tools to view table data or use the<br />
following <strong>SQL</strong> statement:<br />
SELECT * FROM Category<br />
This statement displays all the records in the Category table. Chapter 3 covers the full details of the<br />
SELECT statement. For now, just use it to ensure that the INSERT INTO statement worked.<br />
Once you make sure the first INSERT statement works, you can insert more values into your Category<br />
table:<br />
INSERT INTO Category (CategoryId, Category) VALUES (2, ‘Romance’);<br />
INSERT INTO Category (CategoryId, Category) VALUES (3, ‘Horror’);<br />
INSERT INTO Category (CategoryId, Category) VALUES (4, ‘War’);<br />
INSERT INTO Category (CategoryId, Category) VALUES (5, ‘Sci-fi’);<br />
Now your Category table should contain the following values:<br />
CategoryId Category<br />
1 Thriller<br />
2 Romance<br />
3 Horror<br />
4 War<br />
5 Sci-fi<br />
Check whether yours does by using the following SELECT statement:<br />
SELECT * FROM Category<br />
You can specify the column names in any order you like, so you could also write the above <strong>SQL</strong> as<br />
follows:<br />
INSERT INTO Category (Category, CategoryId) VALUES (‘Historical’, 6);<br />
Regardless of category order, <strong>SQL</strong> performs exactly the same way, as long as you match column names<br />
in the first set of brackets with the correct data in the second set.<br />
If you want to, you can leave off the column names altogether. You can write the code:<br />
INSERT INTO Category (CategoryId, Category) VALUES (6, ‘Historical’)