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 !!!

hkf
  • 4,440
  • 1
  • 30
  • 44
Wassan
  • 63
  • 1
  • 1
  • 5

3 Answers3

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?

Community
  • 1
  • 1
hkf
  • 4,440
  • 1
  • 30
  • 44
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 ,
) 
Novice
  • 558
  • 2
  • 9
  • 21
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)
) 
Devart
  • 119,203
  • 23
  • 166
  • 186