5

I have a problem when i create a table in SQL Server

once i chose DOUBLE as the data type, the error jumped on my face !!!

THIS is the following code :

CREATE TABLE BATCH 
( Product_Name  VARCHAR(200) NOT NULL, 
  Product_Brand VARCHAR(100) NOT NULL, 
  CONSTRAINT Price_FK FOREIGN KEY (Product_Name,Product_Brand)REFERENCES Product   (Product_Name,Product_Brand),
  BATCH_Date AS GETDATE(),
  BATCH_OriginalPrice DOUBLE NOT NULL DEFAULT 0,
  BATCH_TAX DOUBLE NOT NULL DEFAULT 0,
  BATCH_ProductCost DOUBLE NOT NULL DEFAULT 0 ,
) 

The error is like this after each double Incorrect syntax near the keyword 'NOT'

and when i pass the mouse over it, it says " Incorrect syntax near 'NOT'. Expecting ID "

Can someone tell me what's the problem !!!

0

3 Answers 3

11

double isn't a data type in SQL, you'll have to use float or real.

With your example you could use money as well.

related: What represents a double in sql server?

Sign up to request clarification or add additional context in comments.

2 Comments

Complete list of SQL Server data types
But how would i map it in java ? What does represent the [MONEY] in java ?
3

You cannot use DOUBLE in SQL SERVER. Try using Decimal or Float or Real or Money or even Smallmoney. See HERE

CREATE TABLE BATCH 
( Product_Name  VARCHAR(200) NOT NULL, 
  Product_Brand VARCHAR(100) NOT NULL, 
  CONSTRAINT Price_FK FOREIGN KEY (Product_Name,Product_Brand)REFERENCES Product (Product_Name,Product_Brand),
  BATCH_Date AS GETDATE(),
  BATCH_OriginalPrice REAL NOT NULL DEFAULT 0,
  BATCH_TAX REAL NOT NULL DEFAULT 0,
  BATCH_ProductCost REAL NOT NULL DEFAULT 0 ,
) 

Comments

1

Try to use DECIMAL, FLOAT or REAL datatypes -

CREATE TABLE BATCH ( 
    Product_Name VARCHAR(200) NOT NULL, 
    Product_Brand VARCHAR(100) NOT NULL, 
    BATCH_OriginalPrice DECIMAL(18,2) NOT NULL DEFAULT 0, 
    BATCH_TAX DECIMAL(18,2) NOT NULL DEFAULT 0, 
    BATCH_ProductCost DECIMAL(18,2) NOT NULL DEFAULT 0 , 
    BATCH_Date AS GETDATE(), 
    CONSTRAINT Price_FK FOREIGN KEY (Product_Name,Product_Brand)
    REFERENCES Product (Product_Name,Product_Brand)
) 

1 Comment

But how would i represent the these data type in JAVA ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.