5
Lessons > Lesson 1 > Printer Friendly Lesson 1: Printer Friendly Database Basics, and Structured Query Language Chapter 1 Introduction Welcome to Introduction to Structured Query Language. My name is Cecelia L. Allison, and I'll be your instructor throughout the course. My personal experience while learning Structured Query Language (SQL) led me to teach this course. While completing my master of science in computer information systems (MSIS), I found that many books and sources of information on SQL focused more on the software used to implement SQL rather than on the language itself. In this course, I plan to focus extensively on SQL and to provide students with a solid working knowledge of the database/programming language. By the end of this course, you'll understand the basic concepts of relational databases; learn SQL syntax; use SQL to retrieve information from relational databases; use techniques such as joins and subqueries; delete, insert, and update data in tables and views; create tables; and implement some advanced techniques of SQL. In this lesson, I'll provide a foundation for learning the fundamentals of SQL, by exploring the structure of the relational database. I will cover the traditional database structure, the structure and history of the relational database, and what SQL is and how it relates to the relational database. Note: Before you begin this lesson, read the lesson one welcome posting. To view the welcome posting, click on the discussion link. Next, click on the number 1. Finally, click on the welcome posting. Chapter 2 The Database SQL is used to manipulate and retrieve data from relational-database structures. Prior to learning SQL, it is important for you to gain at least a basic understanding of database concepts. Familiarizing yourself with the database structure and concepts will give you a better understanding of SQL and will allow you to grasp the concepts of the language sooner. At some point in your life, you have come in contact with databases. You use them every day. Whether you use the Internet, an ATM machine, or simply a computer-based card-catalog system at a library, you've at least had minimal exposure to a database. It's important that you learn and understand the following terms: client: A single-user computer that interfaces with the multiple-user server. client/server database system: A system that divides processing between client computers and a database server. database: A collection of electronically stored organized files. server: A multiple-user computer that provides shared database connection, interfacing, and processing services. Today the traditional database is referred to as a client/server database system because the processing is divided between client computers and a database server. This division in processing makes it possible for many users to share the information that is stored in the database. The database-system software and interfaces are spread across a network of clients and servers that communicate and cooperate to carry out system objectives.

1-Database Basics and Structured Query Language

Embed Size (px)

DESCRIPTION

Database basics.

Citation preview

Page 1: 1-Database Basics and Structured Query Language

Lessons > Lesson 1 > Printer Friendly

Lesson 1: Printer Friendly

Database Basics, and Structured Query Language

Chapter 1

Introduction

Welcome to Introduction to Structured Query Language. My name is Cecelia L. Allison, and I'll be your instructor throughout the course. My

personal experience while learning Structured Query Language (SQL) led me to teach this course. While completing my master of science in

computer information systems (MSIS), I found that many books and sources of information on SQL focused more on the software used to

implement SQL rather than on the language itself.

In this course, I plan to focus extensively on SQL and to provide students with a solid working knowledge of the database/programming

language. By the end of this course, you'll understand the basic concepts of relational databases; learn SQL syntax; use SQL to retrieve

information from relational databases; use techniques such as joins and subqueries; delete, insert, and update data in tables and views; create

tables; and implement some advanced techniques of SQL.

In this lesson, I'll provide a foundation for learning the fundamentals of SQL, by exploring the structure of the relational database. I will cover the

traditional database structure, the structure and history of the relational database, and what SQL is and how it relates to the relational

database.

Note: Before you begin this lesson, read the lesson one welcome posting. To view the welcome posting, click on thediscussion link. Next, click on the number 1. Finally, click on the welcome posting.

Chapter 2

The Database

SQL is used to manipulate and retrieve data from relational-database structures. Prior to learning SQL, it is important for you to gain at least a

basic understanding of database concepts. Familiarizing yourself with the database structure and concepts will give you a better understanding

of SQL and will allow you to grasp the concepts of the language sooner.

At some point in your life, you have come in contact with databases. You use them every day. Whether you use the Internet, an ATM machine,

or simply a computer-based card-catalog system at a library, you've at least had minimal exposure to a database.

It's important that you learn and understand the following terms:

client: A single-user computer that interfaces with the multiple-user server.

client/server database system: A system that divides processing between client computers and a database server.

database: A collection of electronically stored organized files.

server: A multiple-user computer that provides shared database connection, interfacing, and processing services.

Today the traditional database is referred to as a client/server database system because the processing is divided between client computers

and a database server. This division in processing makes it possible for many users to share the information that is stored in the database. The

database-system software and interfaces are spread across a network of clients and servers that communicate and cooperate to carry out

system objectives.

Page 2: 1-Database Basics and Structured Query Language

A database management system (DBMS) is specialized computer software that is used to create, modify, and update the database; retrieve

data; and generate reports. The core of any database system lies in the DBMS. Some examples include Microsoft Access, DB2, Sybase, and

Microsoft SQL Server.

Database Design

Data Retrieval: One of SQL's main functions is to retrieve data from the database. Because data retrieval is so vital, it is important to note that

creation and population of the database contribute greatly to the success of employing SQL. Consequently, the database must be designed

with the user in mind.

Database Organization: To ensure that your database is effective, you must organize it properly. When you need to retrieve information from

the database, you want it to be easily available. If you don't organize it efficiently, you won't be able to retrieve your data quickly. Remember

that you want your database to be useful; otherwise, it serves no purpose.

A database must also contain accurate and reliable information. Therefore, the data must have integrity. To ensure that your data is accurate

and reliable, it is necessary for the information to be maintained for validity and usefulness.

Chapter 3

Relational Databases

The most widely used type of database is the relational database. Its structure consists of two or more two-dimensional tables that are related

to one another. The data within the tables is stored as a value in a tabular form, and all values in the relational database are accessible through

a combination of table names, primary key values, and column names.

It's important that you learn and understand the following terms:

field: Column that runs vertically within a table.

foreign key: Link records of one type with those of another type.

keys: Uniquely identify a row or record in a table.

normalization: A three-step technique used to organize data attributes in a more efficient, reliable, flexible, and maintainable

structure.

primary key: A field whose value uniquely identifies every row in a table.

row: A record that represents a collection of information relating to an item in a table.

table: Structured file containing rows and columns.

The Structure of a Table

A table is a structured file that contains rows and columns. A column is a field that represents a category of information within a table such as

an address. A row is a record that represents a collection of information relating to an item in a table such as a customer's name, address,

phone number, and social security number (see Fig. 1.1).

Table

Fig 1.1.

Individual records within the table are represented by the rows. The total number of rows in the table is equal to the total number of records in

the table. Every time you add a new row, you are adding a new record to your database.

Relational databases contain many tables. For example, an airline-reservation system could have a table for customers, airlines, departure

times, arrival times, and so on. In order for the database to be relational, these tables must be linked together.

Keys

Page 3: 1-Database Basics and Structured Query Language

To relate two tables to one another (e.g., a table containing customer information, and a table containing order information), you have to use

keys. Keys are used to uniquely identify a row or record in a table. They're similar to DNA. DNA uniquely identifies who we are, and no two

people can have the same DNA. Without a unique identifier, the database cannot identify individual rows.

A primary key is a field whose value uniquely identifies every row in a table. For example, a column representing social security numbers would

be unique because no two people could have the same social security number. The primary key is used to refer to a specific row. The absence

of a primary key makes it difficult to update or delete specific rows.

Another type of key is the foreign key. Foreign keys are pointers to the records of a different file in a database. They link records of one type

with those of another type. The link requires that the foreign key in one table be linked to a corresponding primary key in another table. For

example, to link a customer table to an order table, the customer table containing social security numbers as the primary key must also be a

column within the order table. Yet when you place the social security column within the order table, it is considered a foreign key instead of a

primary key.

Normalization

Normalization is a technique used to organize data attributes in a more efficient, reliable, flexible, and maintainable structure. It is a three-step

technique that places tables in first normal form, second normal form, and third normal form. Well-normalized tables ensure that all of the

tables are linked together. Additionally, the database tends to be more efficient and powerful.

First normal form requires that there must be only one distinct group per table. This involves breaking tables into smaller, more-logical

components and adding primary keys. For example, a table containing columns with more than one type of information—say, retired people,

and people still working for the company—could be broken down into two tables instead of one. You could have one table for the retired people,

and one for the current employees. To make it simpler, you would need to create as many tables as needed to keep all data in separate

groups.

Second normal form states that all columns in a table are dependent on the primary-key column. Simply put, you'll continue to further break

down your tables into more tables if possible. For example, suppose a car dealership has a database that tracks which customers bought

which cars. Suppose they have a table called customer information with the following columns: social security number (primary key), first

name, last name, phone number, address, and car purchased. This table needs to be broken into two tables because the car purchased

isn't dependent on the primary key. The car purchased column should be placed in another table, possibly called car make. The new car

make table would have it's own primary key column possibly called CarMakeID with addtiional columns relating the to the cars..

Third normal form involves reexamining all the groups of information to make sure all data directly relates to the primary key. At this point, if

you still have data that doesn't relate to the primary key, those columns need to be removed.

Chapter 4

Structured Query Language

History

Structured Query Language (SQL) has been around for over twenty-five years. IBM developed it in 1970 from the concept of the relational-

database structure. It was originally called SEQUEL (Structured English Query Language). The first commercial implementation of SQL was in

1979 by Relational Software, Inc., which today is known as the Oracle Corporation.

Current Implementations of SQL

SQL is now widely implemented and is accepted as the industry standard database language. Almost all major database management

systems (DBMSs) support SQL, and all programs written in SQL are portable among most DBMSs.

Some DBMSs use slightly different rules for writing SQL. Basically, however, code written in one DBMS can be moved into another, with a

minimal amount of modification.

SQL Defined

SQL is a nonprocedural language that is used to manipulate and retrieve data from relational DBMSs such as Microsoft Access, DB2, Sybase,

and Microsoft SQL Server. It is considered nonprocedural because of the way operations are carried out. Unlike procedural computer languages

like Basic and C, which are concerned with how to perform operations, SQL describes what needs to be processed. The focus is on what to

retrieve, delete, or insert.

It's a high-level set-oriented language that accesses data stored in tables. Set-oriented refers to the way SQL processes data. To put it simply,

SQL processes sets of data in groups rather than as individual units. You'll be able to process sets of data with a single line of code.

Page 4: 1-Database Basics and Structured Query Language

Functions of SQL

There are a variety of functions that can be performed using SQL. You can modify a database's structure, change system security settings,

add user permissions to databases, query a database for information, and update the contents of a database. As you can see, SQL is

extremely powerful.

Statements and Commands

SQL is made up of a series of keywords or reserved words that allow you to communicate with the database. Keywords are considered

reserved because they are set aside only for the use of querying (questioning) the database. They can't be used to name a database, table,

column, or any other portion of the database or program.

SQL can be used directly by simply typing a series of statements or commands. The most commonly used statement is called the SELECT

statement. The SELECT statement commands the database to retrieve data from the database and return the data to the user.

When using SQL, you command the database to perform a particular action. You command the database to create or delete tables, modify

rows and fields, return results from table searches, and modify security information. This is called querying the database.

A query is a question or command we pose concerning data from the database. Queries are designed to allow users to extract meaningful data

from the database. Each time we use a query, important rules must be followed in order for the request to be processed. The rules are called

syntax—rules that govern how a programming language should be written.

Not following the syntax rules will result in a system error. Therefore, it's a good idea to pay close attention to such things as spacing and

spelling.

Chapter 5

Conclusion

The topics I covered in this lesson included basic database concepts, relational database structure, and SQL. You learned about the traditional

database structure, the structure and history of the relational database, and what structured query language (SQL) is and how it relates to the

relational-database structure.

In chapter 2, I focused on the basic database concepts. Database was defined as "a collection of electronically stored organized files." I

mentioned the traditional database structure and how it is now referred to as a client/server database system. I also defined DBMS and

explained why it's important.

In chapter 3, I focused on the relational-database structure. Relational-database structure was defined as "two or more two-dimensional tables

that are related to one another using keys." I further broke down the relational-database structure by discussing the main attributes that make

up the relational-database system. The chapter concluded with a discussion about the three forms of normalization.

In chapter 4, I focused on structured query language (SQL). SQL was defined as "a nonprocedural language used to manipulate and retrieve

data from relational-database management systems." I covered the concepts and history of SQL and concluded with an explanation of some of

the key terms used with SQL.

This lesson familiarized you with the important concepts pertaining to relational databases, while providing a foundation for in-depth

understanding of SQL.

In lesson 2, you'll learn more about SQL syntax and how SQL is used to sort and retrieve data.

Supplementary Material

A Quick-Start Tutorial on Relational Database Design

http://www.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html

This site discusses the design of the relational-database structure.

Normalization

Page 5: 1-Database Basics and Structured Query Language

Copyright © 1997 - 2014 All rights reserved. The material on this site cannot be reproduced or redistributed unless you have obtained prior written

permission from Cengage Learning.

sql-0

http://www.troubleshooters.com/littstip/ltnorm.html

This site discuses the rules of normalization.

Creating an Oracle Database Table

http://www.pgrocer.net/Cis50/oraclecr.html

This site explains how to create and populate database tables in Oracle.

Introduction to Databases and Microsoft Access

http://www.cs.rochester.edu/~pawlicki/ECOMM/tem/rb/IIIA.htm

This site explains how to export Microsoft Access data into Microsoft SQL Server.

FAQs

Q: Do I need a database management system (DBMS) to practice SQL (e.g., Microsoft Access, DB2, Sybase, or Microsoft Server 7)?

A: No. It is not necessary to purchase a DBMS for this course. Each lesson is accompanied by a quiz and an assignment which will enableyou to practice what you learned. However, if you have a DBMS handy, I encourage hands-on practice.

Q: What database management system (DBMS) is used in the examples throughout the course?

A: This course provides examples using Microsoft Access 2000 and Microsoft SQL Server 7.0. Lessons 1 through 9 use Microsoft Access2000 and Lessons 10 through 12 use Microsoft SQL Server 7.0.

Q: Can I use Microsoft Query for this course?

A: Yes. Microsoft Query uses open database connectivity (ODBC), which means that you can use the same code to access and query datastored in a variety of database management system's (DBMS) with minimum to no modification. It comes packaged with Microsoft Office andmany other Microsoft products. Microsoft Query can be used to connect to tables and queries stored in Microsoft SQL Server or MicrosoftAccess databases.

Assignment

Draw or plan the design of a table. Create a table name, column names, and assign a primary key.

Here is an example of a table named Vehicle within a car dealership database system.

Vehicle table

The serial number column is the primary key in the Vehicle table.

Note: You do not need to complete this assignment within a Database Management System (DBMS). This assignment isintended to enable you to practice creating a name for a table, columns names, and a primary key. Feel free to use pencil andpaper for this assignment.

Back to top