Jump to content

Sql Colum Type


ckrudelux

Recommended Posts

I have keys ( Groups ) to tell which user can do what.. my problem is what I feel it's unnecessary to use "text" for my colum seens it is so big.code I want to save in the colum would look like this:"2, 4, 5, 10, 24, 222, 5240"I don't want to set a limit on how many groups each thing can have and the group id can be more then one number so I can't really tell how much space I will use in the colum.I guess it will take longer time to load text colums from the database then a (int 255)...Hope someone understand my problem here..

Link to comment
Share on other sites

You can use varchar, but you still need to give it a maximum number of characters to allow. Your data is not integer data so you can't use an int column, your data is text data. The normal way to store that type of relationship between objects in your database is to use a separate table. You would include another table with only 2 columns that would say which items are part of the relationship, e.g.:

People-------------------------------------------------------int id	  varchar first_name		varchar last_name1		   Joe					   Thompson2		   John					  Thomas3		   Jeff					  Thomason4		   Frank					 Thomas5		   Fred					  Thomas6		   Fran					  ThompsonParents--------------------------------int parent_id	   int child_id1				   62				   42				   5

The parents table says which children belong to which parent. When you have a one-to-many or many-to-many relationship it's best to use a separate table. A one-to-many relationship means that one parent can have many children, but each child can only have one parent. A many-to-many relationship means that each parent can have many children, and each child can have many parents. A one-to-one relationship means that one parent can have one child, and one child can have one parent. If you have a one-to-one relationship between objects then you can use a single column in your object table to store the parent or child ID, but if you have a one-to-many or many-to-many relationship it's best to use a separate lookup table to store that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...