Lesson 2.5: Defining a Relation Schema in SQL Flashcards
SQL is pronounced as ‘——’
sequel
principal language used to describe and manipulate relational databases
sql
There are two aspects to SQL
- The Data-Definition sublanguage for declaring database schemas and
- The Data-Manipulation sublanguage for querying (asking questions about) databases and for modifying the database.
SQL makes a distinction between three kinds of relations
- Stored relations, which are called tables. These are the kind of relation we deal with ordinarily — a relation that exists in the database and that can be modified by changing its tuples, as well as queried.
- Views, which are relations defined by a computation. These relations are not stored, but are constructed, in whole or in part, when needed.
- Temporary tables, which are constructed by the SQL language processor when it performs its job of executing queries and data modifications. These relations are then thrown away and not stored.
Data types in SQL
Character strings – CHAR(n) and VARCHAR(n)
Bit strings – BIT(n) and BIT VARYING(n)
Boolean
Integer (INT, SHORT INT)
Floating-point numbers (FLOAT, REAL, DOUBLE PRECISION, DECIMAL(n,d), NUMERIC)
date and time (DATE, TIME)
a fixed-length string of up to n characters, implies that short strings are padded to make n characters
CHAR(n)
denotes a string of up to n characters, implies that an end-marker or string-length is used
VARCHAR(n)
denotes bit strings of length n
BIT(n)
denotes bit strings of length up to n
BIT VARYING(n)
type for typical floating-point numbers
FLOAT or REAL
A higher precision of floating numbers can be obtained with the type
DOUBLE PRECISION
allows values that consist of n decimal digits, with the decimal point assumed to be d positions from the right.
DECIMAL(n,d)
is almost a synonym for DECIMAL, although there are possible implementation-dependent differences.
NUMERIC