You're not inserting anything into ID
column of Sales
. You need to specify it in your query:
insert into Sales values(
SomeIDHere,
(select TOP 1 ClientID from Client Order by NEWID()),
(select @prodNum),
(select @quantity),
((select @quantity)*(select TOP 1 Price from Product where ProductNumber = @prodNum)),
DEFAULT
)
But maybe you want to have an autoincrement column for your ID?
CREATE TABLE Sales (
ID INT IDENTITY(1,1) NOT NULL ,
ClientID INT REFERENCES Client(ClientID),
ProductNumber CHAR(10) REFERENCES Product(ProductNumber),
Quantity INT NOT NULL,
Price FLOAT NOT NULL ,
Date TIMESTAMP NOT NULL,
PRIMARY KEY ( ID )
);
In this case, you will need to specify the columns when inserting into Sales
insert into Sales (ClientID, ProductNumber, Quantity, Price, [Date])
values(
(select TOP 1 ClientID from Client Order by NEWID()),
(select @prodNum),
(select @quantity),
((select @quantity)*(select TOP 1 Price from Product where ProductNumber = @prodNum)),
DEFAULT
)