473,695 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whats better?

<usualDisclaime r>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 2028
Muhd (mu**@binarydem on.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**@binarydem on.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**@binarydem on.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
1784
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 sessions access the same application, log messages are interspersed and looks clumsy. And more its hard keep maintaining the log, as components calls among themselves multiple times. what is the better way of maintaining session level log writing to
4
2001
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! Thanks! --
5
1500
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 is the best way to do this? Can I just declare a unsafe pointer as member of a class? Best regards
4
2766
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
72494
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 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
17
1582
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. why? please answer to make me a clear view about C.
5
1678
by: denis | last post by:
Hi there, Whats more efficient and why .... int func(int x) { return x*2; } or
9
4939
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 the constructor method instead. would this make the load time of the program faster? or is it the same as leaving it in the form load.? any thoughts or ideas on this? thanks.
26
3833
by: Muzammil | last post by:
whats the beauty of "malloc" over "new" why its helpful for programmer.for its own memory area.??
0
8572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.