I am new to SQL in general and I’m using Visual Studio for this project. Currently, I have three tables, Item, Orders and Ongoing_Order.
The code for creating the tables are as below:
Item:
CREATE TABLE [dbo].[Item]
(
[itemID] INT NOT NULL PRIMARY KEY IDENTITY,
[itemName] NVARCHAR(MAX) NULL,
[itemPrice] DECIMAL(10, 2) NULL
)
Orders:
CREATE TABLE [dbo].[Orders]
(
orderID INT PRIMARY KEY IDENTITY(10,10),
totalPrice DECIMAL(10,2),
orderDate DATETIME
)
Ongoing_Order:
CREATE TABLE [dbo].[Ongoing_Order] (
[ongoingOrderID] INT NOT NULL IDENTITY(100, 100),
[orderStatus] VARCHAR (50) NULL,
[orderID] INT NULL,
[itemID] INT NULL,
[qty] INT NULL,
CONSTRAINT [PK_Ongoing_Order] PRIMARY KEY ([ongoingOrderID]),
FOREIGN KEY (orderID) REFERENCES Orders(orderID),
FOREIGN KEY (itemID) REFERENCES Item(itemID)
);
The values of the Item table are fixed. The code is supposed to create a new value using the Orders table first and then insert as a foreign key in the Outgoing_Order table. Then, the values from the Items folder along with their quantity will be inserted into the order. Are the tables correct and should I make any correction to it? If not, how can I write the C# code with the SQL prompts needed that can create a new value using the Orders table and subsequently insert the required values into the Outgoing_Order table?
Thye Wei Ping is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.