Hour 2, Defining Data Structures

Team-Fly    

 
Sams Teach Yourself SQL in 24 Hours, Third Edition
By Ronald R. Plew, Ryan K. Stephens
Table of Contents
Appendix C.  Answers to Quizzes and Exercises


Hour 2, "Defining Data Structures"

Quiz Answers

1:

True or false: An individual's Social Security number can be any of the following data types: constant-length character, varying-length character, numeric.

A1:

True, as long as the precision is the correct length.

2:

True or false: The scale of a numeric value is the total length allowed for values.

A2:

False. The precision is the total length, where the scale represents the number of places reserved to the right of a decimal point.

3:

Do all implementations use the same data types?

A3:

No. Most implementations differ in their use of data types. The data types prescribed by ANSI are adhered to, but may differ between implementations according to storage precautions taken by each vendor.

4:

What are the precision and scale of the following?

 DECIMAL(4,2)  DECIMAL(10,2) DECIMAL(14,1) 
A4:
  1. DECIMAL(4,2)

    1. precision = 4, scale = 2

  2. DECIMAL(10,2)

    1. precision = 10, scale = 2

  3. DECIMAL(14,1)

    1. precision = 14, scale = 1

5:

Which numbers could be inserted into a column whose data type is DECIMAL(4,1)?

  1. 16.2

  2. 116.2

  3. 16.21

  4. 1116.2

  5. 1116.21

A5:

The first three fit, although 16.21 is rounded off. The numbers 1116.2 and 1116.21 exceed the maximum precision, which was set at 4.

6:

What is data?

A6:

Data is a collection of information stored in a database as one of several different data types.

Exercise Answers

1:

Take the following column titles, assign them to a data type, and decide on the proper length.

  1. ssn

  2. state

  3. city

  4. phone_number

  5. zip

  6. last_name

  7. first_name

  8. middle_name

  9. salary

  10. hourly_pay_rate

  11. date_hired

A1:
  1. SSN constant-length character

  2. CITY varying-length character

  3. STATE varying-length character

  4. ZIP constant-length character

  5. PHONE_NUMBER constant-length character

  6. LAST_NAME varying-length character

  7. FIRST_NAME varying-length character

  8. MIDDLE_NAME varying-length character

  9. SALARY numeric data type

  10. HOURLY_PAY_RATE decimal

  11. DATE_HIRED date

2:

Take the same column titles and decide whether they should be NULL or NOT NULL, realizing that in some cases where a column would normally be NOT NULL, the column could be NULL or vice versa, depending on the application.

  1. ssn

  2. state

  3. city

  4. phone_number

  5. zip

  6. last_name

  7. first_name

  8. middle_name

  9. salary

  10. hourly_pay_rate

  11. date_hired

A2:
  1. SSN NOT NULL

  2. STATE NOT NULL

  3. CITY NOT NULL

  4. PHONE_NUMBER NULL

  5. ZIP NOT NULL

  6. LAST_NAME NOT NULL

  7. FIRST_NAME NOT NULL

  8. MIDDLE_NAME NULL

  9. SALARY NULL

  10. HOURLY_PAY_RATE NULL

  11. DATE_HIRED NOT NULL

Every individual may not have a phone (however rare that may be) and not everyone has a middle name , so these columns should allow NULL values. In addition, not all employees are paid an hourly rate.

3:

We are going to set up a database in MySQL to use for the subsequent hours in this book. From Windows Explorer, go to the folder where you installed MySQL on your computer. Double-click on the bin folder, and then double click on the executable file called mysql.exe. If you receive an error stating that the server could not be found, first execute winmysqladmin.exe from the bin folder, and then enter a username and password. After the server is started, execute mysql.exe from the bin folder.

At the mysql> command prompt, enter the following command to create a database to use for this book's exercises:

 create database learnsql; 

Be sure to press the Enter key on your keyboard after entering the command. For all subsequent hands-on exercises in this book, you will double-click on the mysql.exe executable, and then enter the following command to use the database you just created:

 use learnsql; 

Team-Fly    
Top
 


Sams Teach Yourself SQL in 24 Hours
Sams Teach Yourself SQL in 24 Hours (5th Edition) (Sams Teach Yourself -- Hours)
ISBN: 0672335417
EAN: 2147483647
Year: 2002
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net