Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am kind of new to SQL Server. I am a CS student so I need helps! (don't have school right now, self learning)

I am wondering if there is a way to have a list of tables(List name) and each of those list names has a list of messages(strings)?

or is there a type of way I could store this data so it can be retained each time I changed it? I was thinking of having it retained through an SQL server. But I am not sure how I could store it.

This is the thing i'll be messing with.
List<LinkData>

class LinkData{
public string listName;
public LinkedList<string> messages;
}
Posted

1 solution

In RDBMS, this is modeled as two tables with a one-to-many relationship: table M with messages has a foreign key to the table N, with list names:
SQL
create table N (
    id bigint identity primary key
,   listName varchar(max)
)

create table M (
    id bigint identity primary key
,   n_id bigint not null references N(id)
,   message varchar(max)
)
Be prepared that RDBMS is a big paradigm shift from what you've seen in "imperative" programming with traditional algorithms and data structures. Don't worry, it will all make sense in time as you work your way through a few dozen examples.

Good luck!
 
Share this answer
 
Comments
Member 8015046 7-Jul-11 12:00pm    
Hahaha I don't understand that. I am using Microsoft SQL management studio. I have made two tables. One with one column that has listName, and another table with one column that has messages. Is there anything I need to change? And how do I make them related? I am messing with database diagrams right now.
fjdiewornncalwe 7-Jul-11 12:43pm    
Your initial table requires a unique id that can then be used in a column in the child table as a foreign key. The example above shows what the table layouts should be.
dasblinkenlight 7-Jul-11 12:18pm    
> Hahaha I don't understand that.
You need some theoretical background then - first few chapters of any book on RDBMS would greatly improve your understanding.
> Is there anything I need to change?
Yes, you need to add id columns to both tables, and a foreign key to the table with messages. Adding a foreign key makes tables related. You can copy-paste the declarations from the answer into a query in SQL management studio, and look at the resulting diagram for tables N and M.
Member 8015046 7-Jul-11 14:08pm    
So if I wanted to add information. Do I add the listName in Table N, then go to table M and have the n_id = listName's id, then put the message?
dasblinkenlight 7-Jul-11 14:14pm    
Correct, that's how you do insertions. Deletions are generally done in reverse order, although you could also use a cascading delete.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900