Saeed Areffard
Saeed Areffard

Reputation: 179

how to use stack or queue as datatype or use it in a column in SQL server

I created a table

tbl_order 
(orderID(pk) ,orderedItems , date , customerID(Fk))

and

tbl_foods 
(foodID(PK),foodname)

I want to store food IDs in orderedItems column

example in

tbl_Order

(orderID=1 , orderedItems(stack(1,4,5,7)), .... ) 1 ROW in tbl_Order

is it possible to do this in SQL server?

Upvotes: 0

Views: 67

Answers (1)

Brian
Brian

Reputation: 1248

It's possible, but it's so bad an idea that you need a new word for "bad". I recommend an approach like this:

Customer
    ID
    Name
    etc.

Food
    ID
    Name
    Description
    etc.

Order
    ID
    Date
    CustomerID

OrderItem
    ID
    OrderID
    FoodID

Note: in each table, "ID" is the primary key, and "table-nameID" is a foreign key into "table-name".

The "queue" and "stack" behavior goes in your front-end code - concepts like that hardly ever have a place in an RDBMS.

Let me know if you have any questions.

Upvotes: 1

Related Questions