user1126245
user1126245

Reputation: 15

Nested table in mysql database

I have created a database like this

+----------------+------------------+
|   name         | password         |
+----------------+------------------+
|   john         | ********         | 
+----------------+------------------+
|   james        |  &*^^%^          |
+----------------+------------------+

Is there any way to create a new table row by column friend,messages, and message from for john and james and other those who join my site?

Upvotes: 0

Views: 4570

Answers (3)

red-X
red-X

Reputation: 5128

you would need consider your database design to include those features. you'll need to add new tables that have a relation to your usertable. Before starting this I would suggest you learn a bit more about relational database design, if you dont you'll get in trouble later on and will need to start it all over.

take a look here, looked like a decent tutorial.

Upvotes: 0

Konerak
Konerak

Reputation: 39773

You could add those columns to your table, but putting that kind of information in the user table is a bad idea.

You should create new tables and use a JOIN to fetch the data:

First, add an ID column to your existing table.

|----------------|------------------|------------------|
|   ID           | user             | password         | 
|----------------|------------------|------------------|

Then, create a new table with the wanted columns:

Table friends:

  • ID
  • USER_ID_FRIEND
  • USER_ID_FRIENDEE

Table messages

  • ID
  • USER_ID_FROM
  • USER_ID_TO
  • DATE_SENT
  • READ
  • MESSAGE_TXT

Upvotes: 4

silly
silly

Reputation: 7887

http://dev.mysql.com/doc/refman/5.1/de/alter-table.html

ALTER TABLE your_table
    ADD COLUMN friends TYPE NULL;

Upvotes: 0

Related Questions