urQL/docs/create.md

114 lines
3.3 KiB
Markdown
Raw Normal View History

2022-08-06 17:06:18 +03:00
`CREATE DATABASE <database-name>`
Example:
`CREATE DATABASE my-database`
2022-08-14 00:20:30 +03:00
Discussion:
`CREATE DATABASE` must be the only command in a script. The script will fail if there are prior commands. As the first command it will succeed and subsequent commands will be ignored.
2022-08-06 17:06:18 +03:00
### _______________________________
2022-08-10 23:23:12 +03:00
```
CREATE [ UNIQUE ] [ NONCLUSTERED | CLUSTERED ] INDEX <index-name>
ON [ <db-qualifer> ]{ <table-name> | <view-name> }
( <column-name> [ ASC | DESC ] [ ,...n ] )
```
2022-08-06 17:06:18 +03:00
Examples:
2022-08-10 23:23:12 +03:00
```
CREATE INDEX ix_vendor-id ON product-vendor (vendor-id);
CREATE UNIQUE INDEX ix_vendor-id2 ON dbo.product-vendor
(vendor-id DESC, name ASC, address DESC);
CREATE INDEX ix_vendor-id3 ON purchasing..product-vendor (vendor-id);
```
2022-08-06 17:06:18 +03:00
Discussion:
2022-08-10 21:45:17 +03:00
Index name cannot start with 'pk-' as these names are internally reserved for primary keys.
2022-08-06 17:06:18 +03:00
A table or view can only have up to one `CLUSTERED` index, including the primary key for tables.
The `UNIQUE` option is not available for views.
### _______________________________
2022-08-10 21:45:17 +03:00
`CREATE NAMESPACE [<database-name>.]<namespace-name>`
2022-08-06 17:06:18 +03:00
Example:
`CREATE NAMESPACE my-namespace`
### _______________________________
2022-08-21 22:12:55 +03:00
```
{ CREATE | ALTER } { PROC | PROCEDURE }
[<db-qualifer>]<procedure-name>
[ { #<parameter-name> <data-type> } ] [ ,...n ]
AS { sql_statement [ ;...n ] }
```
Discussion:
TBD
Cannot create database.
### _______________________________
2022-08-10 23:23:12 +03:00
```
CREATE TABLE
[ <db-qualifer> ]<table-name>
( <column-name> { { <aura> | u( {<aura>) } [DEFAULT <constant_expression>] }
[ ,... n ] )
PRIMARY KEY [ NONCLUSTERED | CLUSTERED ] ( <column-name> [ ,... n ] )
[ { FOREIGN KEY <foreign-key-name> ( <column-name> [ ASC | DESC ] [ ,... n ] )
REFERENCES [ <namespace-name>. ] <table-name> ( <column-name> [ ,... n ]
[ ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
[ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ] }
[ ,... n ] ]`
```
2022-08-06 17:06:18 +03:00
Example:
2022-08-10 23:23:12 +03:00
```
CREATE TABLE order-detail
(invoice-nbr @ud, line-item @ud, product-id @ud, special-offer-id @ud, message @t)
PRIMARY KEY CLUSTERED (invoice-nbr, line-item)
FOREIGN KEY fk-special-offer-order-detail (productid, specialofferid)
REFERENCES special-offer (product-id, special-offer-id)
```
2022-08-06 17:06:18 +03:00
Discussion:
`PRIMARY KEY` must be unique.
`SET NULL` only applies to columns defined as `unit`. Columns defined otherwise will be treated as the default `NO ACTION`.
`SET DEFAULT` applies the column's default constant, if available, otherwise the bunt of the aura.
### _______________________________
2022-08-10 23:23:12 +03:00
```
CREATE TRIGGER [ <db-qualifer> ]<trigger-name>
ON { <table-name> | <view-name> }
[ ENABLE | DISABLE ]
```
2022-08-10 21:45:17 +03:00
TBD hoon triggers
2022-08-06 17:06:18 +03:00
Discussion:
Not for initial release.
### _______________________________
`CREATE TYPE <type-name>`
TBD
Discussion:
Probably will be available only at server (ship) level, and so shared by all databases.
Possibly part of initial or early release.
### _______________________________
2022-08-10 23:23:12 +03:00
`CREATE VIEW [ <db-qualifer> ]<view-name> AS <query>`
2022-08-06 17:06:18 +03:00
Discussion:
Views are read only.
2022-08-10 21:45:17 +03:00
When a column is derived from an arithmetic expression, a function, or a constant; or when two or more columns may otherwise have the same name, typically because of a join; distinct column names must be assigned in the SELECT statement using AS. Otherwise view columns acquire the same names as the columns in the SELECT statement.