Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

Chapter 3 54 MemberId FirstName 1 Katie 3 Sandra 4 Steve 5 John 6 Jenny 7 John 8 Jack 9 Seymour The order of the results in the example database table usually reflects on the order in which the records were first entered into the database, but the order is not guaranteed, so don’t worry if your order looks different from what appears in the preceding table. Chapter 4 shows you how to create a columns index on columns to determine the order of results. Later in this chapter, you learn how to use the ORDER BY clause to specify the order in which records are returned. Specifying which columns you want returned is fine, but sometimes you may want all of the columns, which is a lot of typing if your table has many fields. The good news is that SQL provides a shorthand way of selecting all the columns without having to type out all their names. Instead of typing the column names, just type an asterisk: SELECT * FROM Location; The preceding code fragment is the same as writing the following: SELECT LocationId, Street, City, State FROM Location; Both lines of code return the following results: LocationId Street City State 1 Main Street Orange Town New State 2 Winding Road Windy Village Golden State 3 Tiny Terrace Big City Mega State However, use shorthand only when you need all the columns, otherwise you make the database system provide information you don’t need, which wastes CPU power and memory. Memory and CPU power may not matter on a small database, but they make a huge difference on a large database being accessed by many people.

Chapter 3<br />

54<br />

MemberId FirstName<br />

1 Katie<br />

3 Sandra<br />

4 Steve<br />

5 John<br />

6 Jenny<br />

7 John<br />

8 Jack<br />

9 Seymour<br />

The order of the results in the example database table usually reflects on the order in which the records<br />

were first entered into the database, but the order is not guaranteed, so don’t worry if your order looks<br />

different from what appears in the preceding table. Chapter 4 shows you how to create a columns index<br />

on columns to determine the order of results. Later in this chapter, you learn how to use the ORDER BY<br />

clause to specify the order in which records are returned.<br />

Specifying which columns you want returned is fine, but sometimes you may want all of the columns,<br />

which is a lot of typing if your table has many fields. The good news is that <strong>SQL</strong> provides a shorthand<br />

way of selecting all the columns without having to type out all their names. Instead of typing the column<br />

names, just type an asterisk:<br />

SELECT * FROM Location;<br />

The preceding code fragment is the same as writing the following:<br />

SELECT LocationId, Street, City, State FROM Location;<br />

Both lines of code return the following results:<br />

LocationId Street City State<br />

1 Main Street Orange Town New State<br />

2 Winding Road Windy Village Golden State<br />

3 Tiny Terrace Big City Mega State<br />

However, use shorthand only when you need all the columns, otherwise you make the database system<br />

provide information you don’t need, which wastes CPU power and memory. Memory and CPU power<br />

may not matter on a small database, but they make a huge difference on a large database being accessed<br />

by many people.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!