Lecture No. 3 Structured Query Language
Lecture No. 3 Structured Query Language
Introduction to
SQL
Example:
create table branch
(branch_name char(15),
branch_city char(30),
assets integer)
Domain Types in SQL
char(n). Fixed length character string, with user-specified length
n.
varchar(n). Variable length character strings, with user-specified
maximum length n.
int. Integer (a finite subset of the integers that is machine-
dependent).
smallint. Small integer (a machine-dependent subset of the
integer domain type).
numeric(p,d). Fixed point number, with user-specified precision
of p digits, with n digits to the right of decimal point.
real, double precision. Floating point and double-precision
floating point numbers, with machine-dependent precision.
float(n). Floating point number, with user-specified precision of
at least n digits.
More are covered in Chapter 4.
Integrity Constraints on Tables
not null
primary key (A1, ..., An )
Example: Declare branch_name as the primary key for branch
.
create table branch
(branch_name char(15),
branch_city char(30) not null,
assets integer,
primary key (branch_name))
Find all customers who have a loan at the bank but do not
have
an account at the bank
select distinct customer_name
from borrower
where customer_name not in (select customer_name
from depositor )