PDA

View Full Version : Problema con la creazione di database in SQL


shadow76it
01-09-2003, 17:01
Il mio problema e che adesso mi sto affacciando al mondo della programmazione in SQL ho questo problema. I dati sono copiati da un manuale della Jackson e non capisco l'errore che mi da' in ambiente console.


create table Salespersons
(empid integer not null primary key,
ename char(15) not null,
rank integer not null default 1 check (rank IN (1,2,3)),
salary decimal(5,2) not null
default 100.00 check (salary >=100.00));

create table Customers
(custid integer not null primary key,
cname char(15) not null,
credit char(1) not null check (credit IN ('A','B','C')));

create table Inventory
(partid integer not null primary key,
descriprion char (10) not null,
stockqty integer not null,
recorderpnt integer,
price decimal(5,2) not null);

create table Orders
(ordersid INTEGER not null primary key,
empid INTEGER not null references salespersons(empid),
custid INTEGER not null references customers(custid),
salesdate DATE NOT NULL DEFAULT CURRENT_DATE,
item1 INTEGER REFERENCES Inventory(partid),
qty1 INTEGER,
item2 INTEGER REFERENCES Inventory(partid),
qty2 INTEGER,
item3 INTEGER REFERENCES Inventory(partid),
qty3 INTEGER,
item4 INTEGER REFERENCES Inventory(partid),
qty4 INTEGER,
item5 INTEGER REFERENCES Inventory(partid),
qty5 INTEGER);


mi da questo messaggio
Server: messaggio 156, livello 15, stato 1, riga 24
Sintassi non corretta in prossimitā della parola chiave 'CURRENT_DATE'.
Grazie per l'aiuto

cisky
04-09-2003, 12:57
Se usi SQL Server 7.00 o il 2000 mi sā che ci sono 2 errori ...

create table Orders
(ordersid INTEGER not null primary key,
empid INTEGER not null references salespersons(empid),
custid INTEGER not null references customers(custid),
salesdate DATE NOT NULL DEFAULT CURRENT_DATE ,
item1 INTEGER REFERENCES Inventory(partid),
qty1 INTEGER,
item2 INTEGER REFERENCES Inventory(partid),
qty2 INTEGER,
item3 INTEGER REFERENCES Inventory(partid),
qty3 INTEGER,
item4 INTEGER REFERENCES Inventory(partid),
qty4 INTEGER,
item5 INTEGER REFERENCES Inventory(partid),
qty5 INTEGER)

1) Non esiste la funzione CURRENT_DATE, usa invece GETDATE
2) Non esiste il dataType DATE,usa invece DATETIME

... forse il libro č stato scritto basandosi su una sitassi standard SQL, ma alcune "piccolezze" tipo i datatype ecc.. possono variare a seconda della piattaforma che usi (Oracle,SQL,Access ecc...)

Ciao.