472,993 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Whats better?

<usualDisclaimer>Please forgive me if this is in the wrong group, and if so,
what is the right group.</usualDisclaimer>

Let me start off by first saying im a newb. Ok, with that out of the way I
am trying really hard and boy have I learned a lot in the last little while
but I have a question i just can't seem to find a good answer to.

Lets say i have a table that simply stores how many times someone has logged
into a webpage. Is it better to store each login as a new record then count
the records or is it better to simply have one record that updates the total
value by incrementing that one field. I have read all manner of articles
and some say one way is better vs. the other but what I can't find is why?
If I knew why one way was better than another then I could make and educated
decision and choose the best way that is right for me. Is updating more or
less expensive then inserting? Does it matter and is a relevant question?

And before anyone comments on my use of all uppercase letters for my table
name I do this so that my table names stand out within the sql server
enterprise manager. In other words system tables are lowercase and my
tables are uppercase. People always seem to give me crap for this but never
back it up with a good explanation so far as I can tell its personal
preference? Am I wrong?

CREATE TABLE USER_METRICS
(
-- here i can select all the records and count them up.
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250)
);

-- Or this?

CREATE TABLE USER_METRICS
(
-- and of course here can i simply retrieve the value of Total_Logins
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250) NOT NULL,
Total_Logins INT
);
Regards,
Muhd
Jul 20 '05 #1
3 1998
Muhd (mu**@binarydemon.com) writes:
Lets say i have a table that simply stores how many times someone has
logged into a webpage. Is it better to store each login as a new record
then count the records or is it better to simply have one record that
updates the total value by incrementing that one field. I have read all
manner of articles and some say one way is better vs. the other but what
I can't find is why? If I knew why one way was better than another then
I could make and educated decision and choose the best way that is right
for me. Is updating more or less expensive then inserting? Does it
matter and is a relevant question?
There is no clear-cut answer to this question, because it depends on
what you want. But that said, this table:
CREATE TABLE USER_METRICS
(
-- here i can select all the records and count them up.
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250)
);
does not really make any sense. If this is all you want, then the other
table is much better. It will be faster to use, and take up less disk
space.

But let's say one day, you starting thinking " wonder how often people
log in? Do they make many logins in cluster, or do they log in once an
hour?" Well, this when you want a table like the above, but you add a
login_time column. But even then you may want to keep the other table,
because since if there are many logins, you may prefer to delete old
rows, but still keep the total number of logins since the start of time.
Yet then again, if you only want to know the number of logins the last
two mobths, a table with a row for each login and a timestamp can easily
be emptied at the end of the month, whereas one with only number cannot.

So the bottom line is that to get what you want, you have to know what
you want.
And before anyone comments on my use of all uppercase letters for my
table name I do this so that my table names stand out within the sql
server enterprise manager. In other words system tables are lowercase
and my tables are uppercase. People always seem to give me crap for
this but never back it up with a good explanation so far as I can tell
its personal preference? Am I wrong?


That is of course personal preference. But you may be interested to know
that if you right-click a server in EM, and select Edit SQL Server
Registration Properties, there is a checkbox with which you can hide
system objects.

Personally, I never or very rarely use EM to look at objects, so this
is not an issue for me. My preference is all lowercase for all identifiers,
since I use all uppercase for keywords.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Erland,
Ok one question in response to your message. If your not using EM (and
i don't mean to imply that you should, its certainly helpful for me as a
relative newb) what do you use? Your hiding system objects point was
helpful btw.
So, with that said, thanks for your answer, it did indeed help out alot.
Between the time I wrote my message and the time you answered i did some
thinking about exactly what i was trying to collect, how i was going to use
the data i collected, and was it even important to be collecting in the
first place.
So i decided that yes i did want to know the number of times someone
logged in, but as you pointed out, i also wanted to know when they logged in
and when they logged out. Thus i can track total logins, login time, logout
time, and total time.
Hence i believe this is the best solution for.

CREATE TABLE USER_METRICS
(
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250) NOT NULL
Login_Time DATETIME NOT NULL
Logout_Time DATETIME NOT NULL
)
"Erland Sommarskog" <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
Muhd (mu**@binarydemon.com) writes:
Lets say i have a table that simply stores how many times someone has
logged into a webpage. Is it better to store each login as a new record
then count the records or is it better to simply have one record that
updates the total value by incrementing that one field. I have read all
manner of articles and some say one way is better vs. the other but what
I can't find is why? If I knew why one way was better than another then
I could make and educated decision and choose the best way that is right
for me. Is updating more or less expensive then inserting? Does it
matter and is a relevant question?
There is no clear-cut answer to this question, because it depends on
what you want. But that said, this table:
CREATE TABLE USER_METRICS
(
-- here i can select all the records and count them up.
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250)
);


does not really make any sense. If this is all you want, then the other
table is much better. It will be faster to use, and take up less disk
space.

But let's say one day, you starting thinking " wonder how often people
log in? Do they make many logins in cluster, or do they log in once an
hour?" Well, this when you want a table like the above, but you add a
login_time column. But even then you may want to keep the other table,
because since if there are many logins, you may prefer to delete old
rows, but still keep the total number of logins since the start of time.
Yet then again, if you only want to know the number of logins the last
two mobths, a table with a row for each login and a timestamp can easily
be emptied at the end of the month, whereas one with only number cannot.

So the bottom line is that to get what you want, you have to know what
you want.
And before anyone comments on my use of all uppercase letters for my
table name I do this so that my table names stand out within the sql
server enterprise manager. In other words system tables are lowercase
and my tables are uppercase. People always seem to give me crap for
this but never back it up with a good explanation so far as I can tell
its personal preference? Am I wrong?


That is of course personal preference. But you may be interested to know
that if you right-click a server in EM, and select Edit SQL Server
Registration Properties, there is a checkbox with which you can hide
system objects.

Personally, I never or very rarely use EM to look at objects, so this
is not an issue for me. My preference is all lowercase for all

identifiers, since I use all uppercase for keywords.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 20 '05 #3
Muhd (mu**@binarydemon.com) writes:
Ok one question in response to your message. If your not using EM (and
i don't mean to imply that you should, its certainly helpful for me as a
relative newb) what do you use?
To write ad hoc-queries I use Query Analyzer. For writing stored
procedures and other code that is part of our system I use a third-
party text editor, TextPad. TextPad has on particular SQL support, it
is just a better editor. To load the procedures to the database for
testing, TextPad permits me to invoke a command-line tool which connects
to the database. My load tool is a home-written one that has a lot of
bells and whistles to take care of whether I should use CREATE/ALTER
procedures, permissions and a lot more.

Using a third-party editor is probably a very common solution, but
there are too many persons out there that use the Stored Procedure
window in EM, which has really port editing capabilities. Query Analyzer
is a lot better.

For data-modelleling I use another third-party tool, PowerDesigner which
is a more powerful data-modelling tool than the diagrams you have in
Enterprise Manager.

And to look at the table data - again, I run queries in Query Analyzer.
Hence i believe this is the best solution for.

CREATE TABLE USER_METRICS
(
ID INT IDENTITY(1,1) PRIMARY KEY,
Email VARCHAR(250) NOT NULL
Login_Time DATETIME NOT NULL
Logout_Time DATETIME NOT NULL
)


You should probably make Logout_Time nullable, and write a row when the
user logs in, and then update the row when he logs out. If there is a
crash, he may neevr log out.

Also, the id column may not be necessary, but (Email, Login_Time) is a
natural key here - as long as no evil user manages to login in the
same 3.33 millisecond interval.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

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

Similar topics

1
by: RK | last post by:
Our Application solution consists Web Service and 3 other C# class libraries. We added Trace Listener to the application and writing log information in all our components. Since multiple...
4
by: David Lozzi | last post by:
OK simple question. Whats the default value for an string() array? sub LoadStuff(byval one as integer, byval two as string, optional byval three() as string = ??) Its driving me nuts! ...
5
by: | last post by:
Hi, In our system we get image buffers through a native dll as void*. We want to manage several of this blocks by C# objects an pass them wen needed to a native image processing library. What...
4
by: sophie | last post by:
Whats going on here: Read in a number as a string: scanf("%s", &number); number = 12345, for arguements sake Print it like this its fine:
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
17
by: student | last post by:
hi, C is an evergreen programming language developed by denis richie. C++ is only an extension to C with some extra added features and VC++ provides an IDE for programming. still C is not obselete....
5
by: denis | last post by:
Hi there, Whats more efficient and why .... int func(int x) { return x*2; } or
9
by: =?Utf-8?B?cm9nZXJfMjc=?= | last post by:
hey, I have some preliminary code in my program (check for a certain file, define a like 15 variables) and I put it in the form load. I recently got the idea to make a method for it, and do it in...
26
by: Muzammil | last post by:
whats the beauty of "malloc" over "new" why its helpful for programmer.for its own memory area.??
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.