0

What is the best way to create table in SQL database for my situation? Option 1 or Option 2?

TMyRecord = record
 id : integer;
 name : string;
 price : Array [0.100] of double;

If i want to create table in SQL database,

Option 1: - Creating one table and use ID and Name for all price entries.

CREATE TABLE My_Record
(
ID int,
Name varchar(255),
price float,
); 

or Option 2: - use two tables and link each other?

CREATE TABLE My_Record
(
ID int,
Name varchar(255),
price float,
PRIMARY KEY (P_Id)
);
CREATE TABLE My_Record_ArrayData
(
FOREIGN KEY (ID) REFERENCES My_Record(ID)
price float,
);

Thanks in advance.

3
  • Your second option doesn't show much of a difference from the first, just more useless fluff. In both cases you have trailing commas as well as other seeming syntax errors. Commented Oct 27, 2014 at 3:47
  • You didn't mention DBMS that you'll use. For instance in PostgreSQL you could create exactly such table. Commented Oct 27, 2014 at 7:04
  • If there is a possibility of having multiple prices for the same product, go for option 2 in any other cases option 1 is for you. Commented Oct 30, 2014 at 10:29

1 Answer 1

1

Option 2 is better, as you don't repeat Name column for each price value.

Also you just need to store ID,Name in My_Record in the second option , all price values can go to My_Record_ArrayData

another option is to go with XML data type to store all price values then you will have only one table with all values for that Name.

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

1 Comment

XML data type ? I hope you wasn't thinking of a raw storage of XML files (how would one search by value in such overgrown structure). Even if you were thinking of some sort of (due to missing DBMS in the question) storage when DBMS stores all the values unparsed it looks like an overkill to me.

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.