How can I store arrays in an SQL table
I'm a new with SQL programming. My question is about how to store array values in DB. For example I want to coordinate sketch of some department. let it be an hospital. and I want to put Floor and put room for each floor and put beds for each rooms.
I thought I could fix it if I use some for loop. but I couldn't.
How can I fix that?
Console.Write("enter floor numbers ");
k开发者_如何学运维at = int.Parse(Console.ReadLine());
Console.Write("enter room numbers ");
oda = int.Parse(Console.ReadLine());
Console.WriteLine("enter bed numbers");
yatak = int.Parse(Console.ReadLine());
for ( i = 1; i <= kat; i++)
{
for ( j = 1; j <= oda; j++)
{
for ( k = 1; k <= yatak; k++)
{
Console.WriteLine("total bed numbers {0} {1} {2}", i, j, k);
}
}
If I put 2 for each one, I have to create 8 cell in DB.
Provided you are talking about relational databases, what you need to do is design your tables such that you can store all your objects and the relation between them. In case of the example you have provided
Hospital --> 1..many Floors --> 1..many Rooms --> 0..many Beds
(making general assumptions about the cardinality - just take it as a sample)
Based on the above relation, you would have a table for each noun, i.e. Hospital, Floors, Rooms and Beds. In a relational database one RECORD (not a column) represents one distinct value of the entity represented by a table. So if you have 10 floors in a hospital, there will be 10 records in Floor table.
Each record in a table is uniquely identified by a value referred to as its Primary Key.
Relationships between the Parent and its children tables are done using this Primary Key and creating what is known as a Foreign Key constraint. Basically, to take an example, if Floor 1 has 10 rooms, i will have the floor No i.e "1" in the Room table to be able to know which room belongs to which floor.
Overall, though this is not a direct solution to your question, i hope it helps you enough to be able to read up on the basic RDBMS concepts which is what you need to solve your problem. Key points to look up : Cardinality, Primary Keys and Foreign Keys.
精彩评论