acytoo

Database Advanced SQL

  • JDBC: Java Database Connectivity
  • ODBC: Open Database Connectivity
  • Embedded SQL ...

Embedded SQL

EXEC-SQL connect to server_addr user user_name using password;
EXEC SQL <embedded SQL statement > END_EXEC

EXEC SQL
declare c cursor for
select ID, name
from student
where tot_cred > :credit_amount
END_EXEC
Extensions and stored procedures

SQL provides a module language

Database Intermediate SQL

Join operations take two relations and return as result another relation

A join operation is a Cartesian product which requires that tuples in the two relations match(under some condition). It also specifies the attributes that are present in the result of the join.

Database Er Model

The ER data model employs three basic concepts: entity set, relationship set, attributes.

Entity sets:

An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event, plant

An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays.

Database Introduction to Sql

  • char(n): Fixed length character string, with user-specific length n.
  • varchar(n): Variable length character strings, with user-specific maximum length n.
  • int: Integer
  • smallint: Small integer
  • numeric(p, s): Fixed point number, with user-specific precision of p digits, with s digits to the right of decimal point.
  • real, double precision: Floating point and double-precision floating point numbers
  • float(n): Floating point number, with user-specific precision of at least n digits.
Create table
create table alluser (
  id char(5),
  name varchar(10) not null
)
Drop and alter
drop table alluser
alter table alluser add email varchar(20)

Dropping of attributes not supported by many databases

Database Relational Algebra

  • Procedural language
  • Based on relational operations
  • Three set of RA operations
    • Basic RA operations
      • select, project, union, set diff, cartesian product, rename
    • Additional RA operations
      • Can be expressed using basic ones
      • But make it easier to write queries
      • intersection, assignment joins, division
    • Extended RA
      • Increases power of RA
      • Cannot be expressed with basic RA
      • Aggregation and group_by

Relational Operators

Six basic operators: