Create Index имя список полей
У него нет семантики
В рамках реляционного подхода таблица есть отношения, то есть множество, а в понятии множества порядок перечисления элементов отсутствует, но такой порядок исключительно важен в реализации. Все быстрые алгоритмы поиска (доступа) основаны на некотором упорядочивании компонент файла. Проблема: доступ к разным значениям нуждается в разном порядке компонент. Решение: хранить нужные порядки в разных файлах логически, то есть хранить не сами записи, а ссылки на них. Любая реализация SQL сама создаёт множество индексных файлов, содержащих такие ссылки. В частности, создаются индексы для значений ключевых полей.
Create table Customer (ID integer not null primary key, name char(20), city char(20), credit decimal not null check(credit>=0), birthday date check(year(birthday)>1900))
Create table Employee (ID integer not null primary key, name char(20), city char(20), comm decimal not null default 0, birthday date)
/*comm – доля выручки с заказа*/
Create table Orders (ID integer not null primary key, Cust_Ref integer not null references Customer(ID) //*//, Emp_Ref integer references Employee(ID) //*//, startdate not null, finishdate not null check(startdate<finishdate)
* - имеется первичный ключ по умолчанию
delete ofCustomer cascades
delete of Employee nulls
update ofCustomer cascades
Create table Item (Order_Ref integer not null, Product_Ref integer not null, amount integer not null default 1, unique(Order_Id, Product_Ref), foreign key (Product_Ref) references Product(ID)
/*amount – количество единиц товара*/
Create table Product (ID integer not null primary key, name char(30), price decimal not null check(price>0), type char(10) not null)