DB Lab 1 - Basic SQL Statements
DB Lab 1 - Basic SQL Statements
Table Columns/Fields/Attributes
Rows/Records/Tuples
Characteristics of a Relational Model
Tables are flat: eliminates potential for redundant data & requires primary key
Attributes have types & are static, eg: INT, FLOAT, VARCHAR(20),
DATETIME
Order of the records does not matter, but duplicate records violate rules
(semantics)
Characteristics of a Relational Model
Assuming the attribute “Salary” is of Sub-tables are not allowed, additional
type INT, the first record in this table data can be stored in other tables with
violates the attribute type. relations
What is SQL?
Structured Query Language
Declarative query language, which is a critical tool for data analysis
Other languages like Python/Java are Procedural languages
With declarative languages, you tell the computer what you want, not how to get
it
Declarative query languages allow physical data independence, meaning
physical storage level is changed without affecting conceptual view of data
SQL “SELECT” Statement
SELECT [DISTINCT]{*, column [[as] alias],...}
FROM table;
Table 1 Table 2
Selecting All Columns
SQL> SELECT *
2 FROM dept;
DEPTNO LOC
--------- -------------
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
Column Heading Deafults
Default justification
◦ Left: Date and character data
◦ Right: Numeric data
DEPTNO DEPTNO
--------- ---------
10 10
30 20
10 30
20
...
14 rows selected.
The default display of queries is all rows, including duplicate
rows
Eliminate duplicate rows by using the DISTINCT keyword in
the SELECT clause
Displaying Table Structure
SQL> DESC dept