473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to format a database with a field that has a table or list?

Can someone help me to define a format of a database, or a table that has a
field that will have tables in that field? Please look at the example and
explanation below:

Table: Roster

---------------------------------------------------
|User Name | User ID | Status | Daily Activity Log |
---------------------------------------------------
|John Doe | 1001 | Active | (Tabulated activity)|
---------------------------------------------------
|Mary Doe | 1002 |inactive| (Tabulated activity)|
---------------------------------------------------

Above is a brief description of the table. I would like for the last field
to be a table (or table like) format or list that will include a number of
fields of the users' activity. One user might have one or two items in his
list. Another person might have 10 or 100 items in their list. The
table-like list of the daily activity log column will include something like
the following:

1) Date/time of activity
2) Number of people involved in this session
3) Total time of this session
4) Location of the session
5) Session rating (completed/incomplete)

The activity log field may have 10 of these entries in one day. The next
day it might have 5 entries in this field. The following 3 or four days
there might not be any entries.

Thanks in advance for any comments on this matter. Hopefully someone will
get the gist and put a more educational description to my objective.
-- L. D. James
--
-----------------------
L. D. James
lj****@apollo3.com
www.apollo3.com/~ljames

Jul 23 '05 #1
3 1447
L. D. James wrote:
I would like for the last field
to be a table (or table like) format or list that will include a number of
fields of the users' activity. One user might have one or two items in his
list. Another person might have 10 or 100 items in their list. The
table-like list of the daily activity log column will include something like
the following:
This should be done in a second table, which references the roster table.
1) Date/time of activity
2) Number of people involved in this session
3) Total time of this session
4) Location of the session
5) Session rating (completed/incomplete)


CREATE TABLE roster_activity (
user_id INTEGER NOT NULL REFERENCES roster(`User ID`),
activity DATETIME NOT NULL,
num_people INTEGER NOT NULL DEFAULT 1,
session_minutes INTEGER NOT NULL DEFAULT 0,
session_location VARCHAR(200) NOT NULL,
session_rating TINYINT NOT NULL DEFAULT 0
);

Now you can get all the activity for a user thus:

SELECT r.*, a.*
FROM roster AS r INNER JOIN roster_activity AS a
ON r.`User ID` = a.user_id
WHERE r.`User ID` = 1001;

This returns a separate row for each activity of that user.

Regards,
Bill K.
Jul 23 '05 #2
"Bill Karwin" <bi**@karwin.com> wrote in message
news:d3*********@enews3.newsguy.com...
L. D. James wrote: CREATE TABLE roster_activity (
user_id INTEGER NOT NULL REFERENCES roster(`User ID`),
activity DATETIME NOT NULL,
num_people INTEGER NOT NULL DEFAULT 1,
session_minutes INTEGER NOT NULL DEFAULT 0,
session_location VARCHAR(200) NOT NULL,
session_rating TINYINT NOT NULL DEFAULT 0
);


Bill. Thanks a bunch for the quick and incrediable clear response.

-- L. James

--
--------------------------------
L. D. James
lj****@apollo3.com
www.apollo3.com/~ljames
Jul 23 '05 #3
"Bill Karwin" <bi**@karwin.com> wrote in message
news:d3*********@enews3.newsguy.com...
L. D. James wrote: CREATE TABLE roster_activity (
user_id INTEGER NOT NULL REFERENCES roster(`User ID`),
activity DATETIME NOT NULL,
num_people INTEGER NOT NULL DEFAULT 1,
session_minutes INTEGER NOT NULL DEFAULT 0,
session_location VARCHAR(200) NOT NULL,
session_rating TINYINT NOT NULL DEFAULT 0
);

Now you can get all the activity for a user thus:

SELECT r.*, a.*
FROM roster AS r INNER JOIN roster_activity AS a
ON r.`User ID` = a.user_id
WHERE r.`User ID` = 1001;

This returns a separate row for each activity of that user.


Bill (or anyone else familiar with the Perl interface to Mysql), as I
mentioned, the formula you gave works ill (or anyone else familiar with the
Perl interface to Mysql), as I mentioned, the formula you gave works
perfect. I've created the database, and can very easily enter, maintain and
view the data. Now I'm trying to make an easy interface for others to enter
and maintain.

I installed the Mysql module to Perl. I'm able to connect to the database.
View the data and structure. However, I can't figure out the "Insert"
command or option.

Can someone give me a sample line that will insert a basically do the
following from Perl:

Mysql> INSERT INTO roster_activity (1001,DATETIME,5,100,"498 Northland
Avenue",100);

The database was opened using the following:

-----------------------------
#!/usr/bin/perl
use Mysql;

$host = 'localhost';
$database = "mybase";
$user = "user";
$password = "mypassword";

$db = Mysql->connect($host, $database, $user, $password);
$db->selectdb($database);
@tables = $db->listtables;

foreeach $table (@tables)
{
print "$table\n";
}

# Here is where I would like to insert the code to insert a new record into
# the roster_activity table.
-----------------------------

Thanks in advance for any suggestions or comments.

-- L. D. James
--
--------------------------------
L. D. James
lj****@apollo3.com
www.apollo3.com/~ljames
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Thompson | last post by:
Looking for a book to help me develop a philosophy for building databases (particularly on MySQL). And then taking them from concept to construction. Something like.... Start by asking which...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
76
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
10
by: Dixie | last post by:
I am appending some new fields to a table in vba and when I append a number field with is a byte, it does not inherit any format. I want it to be the General Number format, but it is blank. I...
2
by: NasirMunir | last post by:
I have created a table in access (copied from excel). Then I created a form which contains a text field and a list box. The text field is actually a look-up field, where a user can enter a searchable...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.