Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I keep getting an incorrect syntax near message when I type this code

where it says "Not" on the price double section and "(publisher_id));" on the last section . what should I do??

What I have tried:

SQL
use bookstore
CREATE TABLE book (
book_id int PRIMARY KEY,
isbn VARCHAR(100) NOT NULL,
title VARCHAR(100) NOT NULL,
print_year int NOT NULL,
edition int NOT NULL,
price double NOT NULL,
publisher_id int FOREIGN KEY REFERENCES
publisher(publisher_id)
);
Posted
Updated 8-May-22 17:36pm
v2
Comments
Mike Hankey 8-May-22 21:08pm    
Comma at end of line after REFERENCES i.e. ...REFERENCES,

1 solution

Both PostgreSQL and sqlite choke on
SQL
publisher_id FOREIGN KEY REFERENCES publisher(publisher_id)
In both cases removing FOREIGN KEY solved the issue. PostgreSQL did not like the field type of double, as I believe float is the standard type for a floating point field. That being said, a field representing a monetary value is probably better represented as a NUMERIC type, rather than a binary floating point. That's due to the nature of binary floating point, which cannot represent 0.01 exactly. To see this for yourself, try this in your favorite compiled language:
PsueoCode
double d = 0.0;
for 1 ... 100 
   d = d + 0.01

if d == 1.0
    print yes
else
    print no
The result may not be what you expect!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900