IBM Sequel language developed as part of System R project at the IBM San Jose Research Laboratory. It renamed as SQL short for Structured Query Language. But still, it can be called as Sequel. Commercial systems offer most, if not all, SQL-92 features, plus varying feature sets from later standards and special proprietary features. So not all examples here may work on your particular system. FYI, I will use SQLite from now on. :)
The SQL data-definition language(DDL) allows the specification of information about relations, including the schema for each relation, the domain of values associated with each attribute, integrity constraints and other information such as the set of indices to be maintained for each relation, security and authorization information for each relation and the physical storage structure of each relation on disk.
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 -
- smallest: Small integer - a machine dependent subset of the integer domain type -
- numeric( p, d): Fixed point number. with the user-specified precision of p digits, with d or the p digits to the right of decimal point.
- ex) numeric( 3, 1): 44.5 to be stored exactly, but, neither 444.5 nor 0.32 can be stored exactly
- real, double precision: Floating point and double-precision floating point numbers, with machine-dependent precision.
- float(n): floating point number, with a user-specified precision of at least n digits.
- ...
Create Table Construct
An SQL relation is defined using the create table command:
ex) create table instructor ( ID char(5), name varchar(20), dept_name varchar(20), salary numeric(8, 2))
If you want to insert the data into the table using this command:
ex) insert into instructor values ( '10211', 'Smith', 'Biology', 66000)
And * means all, so the command - select * from 'table name' - will show us the whole table. I ran the insert row twice so there are 2 Davids in the table.
Integrity Constraints in Create Table
Command [ not null ] guarantee the variable cannot be the null value.
Also, there are commands about primary key and foreign key. For example, declare dept_name as the primary key for 'department'. Primary key declaration on an attribute automatically ensures not null. In case of the foreign key, the values of attributes (Am, ..., An) for any tuple in the relation must correspond to values of the primary key attribute of some tuple in relation r. For example, declare dept_name as the foreign key for 'instructor'. For each 'instructor' tuple, the department name specified in the tuple must exist in the primary key attribute (dept_name) of the department relation.