Sunteți pe pagina 1din 8

SQL 101: A B EGINNERS GUIDE TO SQL Introduction to SQL

INTRODUCTION TO SQL
What the Heck is SQL?

Structured Query Language MS SQL Server


uses a dialect
called T-SQL
• SQL is a language that lets you access
and manipulate databases
• SQL is an ANSI (American National
Standards Institute) standard •SQL can execute queries against a database
–Although there are different dialects •SQL can retrieve, insert, update and delete data
•SQL can create new tables in a database
•SQL can create reusable blocks of code
TABLE AND COLUMN
STRUCTURE
Database Table Column

• A database is a • The information • The data itself is


container that inside the database is organized in columns
holds tables and organized into tables and rows
other SQL • A table is the
structures related structure inside your
to those tables database that
contains columns and
rows
DATA TYPES IN SQL
RELATIONAL DATA AND
NORMALIZATION
What Makes a Database "Relational"?

Artist Album_1 Album_2 Album_3

Britney Spears Baby One Oops I did it Again Britney


More Time

Backstreet Boys Backstreet Backstreet’s Back Millennium


Boys

LFO LFO

• Compare information because of the arrangement of data in columns


• Build completely new tables out of required information from existing tables
• Uses the relationship of similar data to increase the speed and versatility of the database.
RELATIONAL DATA AND
NORMALIZATION
What is Normalized Data?
• No repeating groups of data
Why Does it Matter?
• All non-key attributes are
• Eliminating redundant
dependent on a primary key
data
• All non-key attributes are ONLY
• Ensuring data
dependent on a primary key
dependencies make
• In a perfect world attributes that sense
can be calculated based upon other
attributes should be removed
RELATIONAL DATA AND
NORMALIZATION
AlbumKey AlbumName Artist ArtistKey Artist

1 Baby One More 1 1 Britney Spears


Time
2 Backstreet Boys
2 Backstreet Boys 2
3 LFO
3 LFO 3

4 Oops I did it Again 1

5 Britney 1

• How can we connect the Tables?


6 Backstreet’s Back 2
• Why don’t we just put the Artist
7 Millennium 2 Name in the Album Table?
PRIMARY AND FOREIGN KEYS
There are three types of table relationship:
 One to one
 One to many
 Many to Many

 A Primary key is a key that uniquely identifies a row in each table. It is normally denoted
with its first two letters, namely, PK.
 A Foreign key is a key borrowed from another related table (that’s why its foreign) in
order to make the relationship between two tables. It is normally denoted with its first two
letters, namely, FK.

S-ar putea să vă placă și