Showing posts with label pretty. Show all posts
Showing posts with label pretty. Show all posts

Tuesday, March 27, 2012

Basic Question on Join

Hi,

I'm pretty much a database beginner and have what I think is a basic
question:

If I have a table which has a 'status' column and I can have say three
statuses: "active", "pending", "inactive". Is it better to break these
out into a different "Statuses" table?

On the one hand it seems to me it would be better to be in a different
table since I'll index this column because I'll be in a where clause
sometimes and I think indexing it would be easier than indexing the
actual words. On the other hand, are joins going to slow queries down
too much? I read something about creating my own sql server 2000
datatype - would this be a good place to do such a thing?

Thanks for your help. (And if you could provide a reason why one
solution is better than the other so I can start understanding better,
I'd be very appreciative.)

Thanks.nick wrote:
> Hi,
> I'm pretty much a database beginner and have what I think is a basic
> question:
> If I have a table which has a 'status' column and I can have say three
> statuses: "active", "pending", "inactive". Is it better to break these
> out into a different "Statuses" table?
> On the one hand it seems to me it would be better to be in a different
> table since I'll index this column because I'll be in a where clause
> sometimes and I think indexing it would be easier than indexing the
> actual words. On the other hand, are joins going to slow queries down
> too much? I read something about creating my own sql server 2000
> datatype - would this be a good place to do such a thing?
> Thanks for your help. (And if you could provide a reason why one
> solution is better than the other so I can start understanding better,
> I'd be very appreciative.)
> Thanks.

If you're storing addresses should you have 50 separate tables, one for
each state?

Zach|||"nick" <nickgieschen@.hotmail.com> wrote in message
news:305cab98.0411191325.29e48efc@.posting.google.c om...
> Hi,
> I'm pretty much a database beginner and have what I think is a basic
> question:
> If I have a table which has a 'status' column and I can have say three
> statuses: "active", "pending", "inactive". Is it better to break these
> out into a different "Statuses" table?
> On the one hand it seems to me it would be better to be in a different
> table since I'll index this column because I'll be in a where clause
> sometimes and I think indexing it would be easier than indexing the
> actual words. On the other hand, are joins going to slow queries down
> too much? I read something about creating my own sql server 2000
> datatype - would this be a good place to do such a thing?
> Thanks for your help. (And if you could provide a reason why one
> solution is better than the other so I can start understanding better,
> I'd be very appreciative.)

Having a seperate lookup table may give you a better performance, testing is
the best way to determine. The lookup table could have an numeric value
that corresponds to active, pending, inactive and then you store the numeric
value in your main table. You wouldn't necessarily have to join to the
lookup table, you could just say WHERE Status = 1.

Using lookup tables can be more flexible for front-end coding because if
you have additions to your lookup choices you can simply edit the table
rather than digging around in the front-end code.

I wouldn't think a user-defined datatype would be useful for this.

hth|||nick (nickgieschen@.hotmail.com) writes:
> I'm pretty much a database beginner and have what I think is a basic
> question:
> If I have a table which has a 'status' column and I can have say three
> statuses: "active", "pending", "inactive". Is it better to break these
> out into a different "Statuses" table?
> On the one hand it seems to me it would be better to be in a different
> table since I'll index this column because I'll be in a where clause
> sometimes and I think indexing it would be easier than indexing the
> actual words. On the other hand, are joins going to slow queries down
> too much? I read something about creating my own sql server 2000
> datatype - would this be a good place to do such a thing?

Basic question? It is actually one that I run into when I'm database design
every now and when, and the answer is not always the same. Mainly it is a
judgement's call. But these days, I tend to go for the table.

I like to first point that when I decide whether to add a table, or to
just have a column with some distinct values, performance has none to with
that decision. More important is the aspect of maintenance, the possibility
to present the value, extensibility and whether the value is important
enough to deserve a table.

Having a single column like:

status chat(1) NOT NULL CHECK (status IN ('A', 'P', 'I'))

has the advantage that it's up little space in the documentation, and
so easier to grasp. But if the value is to be presented in a GUI, the
GUI gets responsible for doing the translation (or the user gets to see
A, P and I. Another issue, is whether you need to add a new value. For
various reasons when we change tables, our standard routine is to take
the long way and reload the data into a new table. A bit expensive for
a changed CHECK constraint.

If you have a column with a lookup-table like:

status char(1) NOT NULL REFERENCES statusvalues (status)

this is more work for me initially, because I have to create an INSERT-
file with the statusvalues, and there is one more table in the database.
(In our case actually two, because there would also be a name table
that gives translations in different languages.). But if I later need
to add a new value, it's just a matter of changing that INSERT-file and
no need to reload the table. And with all strings in the database, the
GUI gets a simpler job.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

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

Saturday, February 25, 2012

Backups

Hi Guys,

I'm pretty new to SQL Server. I have a ? regarding backups.

I have a database which I'm backing up everyday using BACKUP DATABASE db TO db_bak WITH INIT. This job runs everyday successfully, but I'm having an evergrowing transaction log file. I presumed a full database backup will apply transaction logs and will truncate the log files. Isnt it so, or am i missing some concepts? This database can have a data loss of 1 day which is covered by my full database backup job. I dont need a transaction log backup. But to reduce log file size should I do a log backup?

-Sunil.Depends...(love that answer)

What's your recovery model? Simple would do what you're thinking...

I have a feeling it's FULL...in which case you need to dump the tranny too...

Look at the maint plan wizard to help you out

Also you need to determine what type of strategy you need to employ...

Basically, how much time/data can you afford to lose...|||Thanks Brett,

My recovery model is FULL and i prefer to keep it that way. So, i reckon I should set transaction log backups aswell. I have set database backup to run every 6PM, if i create another job to backup transaction logs at 7PM, will it do? Also, since my database is big (It is MSProject database) database backup is done everyday in overwrite mode to avoid appending 200MB everyday to the backup file. Could transaction log backup be done in overwrite mode aswell or is it necessary to be appended every day? If there is a recovery scenario, will it all add well?

I'm still wondering why isnt transaction log truncated after a successful full backup. Why do we need transaction logs if the database itself is fully backed up.

-Sunil.|||Originally posted by sunilthomas98
I'm still wondering why isnt transaction log truncated after a successful full backup. Why do we need transaction logs if the database itself is fully backed up.
-Sunil.

Because it is a point in time backup...logs are usually dumped periodically to recover data throughout the daya (I do mine every 10 minutes)

Why not first go through the db maint wizard...it'll show you all the things you can do, without having to code them in T-SQL...it'll even schedule the jobs...

Then by a book...one of my favorites is SQL Server 911 by Brian Knight..good book

Here's a real story...

HR "dba" (the quotes are on purpose) had the type of scenario you mention..

It was time to enter in all the work for the bonuses...which got done...

Now scrub boy messed something up...we think he had a glitch a decided to recover the db from last nights dump...effectivley wiping out all the work the clerks had enetered...soooooo no bonuses...right?

Wrong...the vp called ALL of the clerks in plus IT staff to re-enter the data...so at about 4:00 am it was done...and the file went out the next day...

He's not with us anymore...|||Thanks Brett, I'll do that not to miss my next bonus (if it comes)

Friday, February 10, 2012

Backup to Flash Drive

I have a utility I wrote which can backup/restore my database as well
as schedule backups. This has always worked pretty well except when I
try to backup to a USB Flash Disk. When I use one of these the backup
fails. If I backup to the C:/ drive then copy it over to the disk it
works fine but when SQL Server tries to do it, it can't.
I am simply doing the following:

BACKUP DATABASE MyDatabase TO DISK = 'E:/backup.dat_bak' WITH INIT

Anyone know what could be going wrong?"Ray Lavelle" <bostonpartykid@.yahoo.com> wrote in message
news:d8653140.0309032311.36f02596@.posting.google.c om...
> I have a utility I wrote which can backup/restore my database as well
> as schedule backups. This has always worked pretty well except when I
> try to backup to a USB Flash Disk. When I use one of these the backup
> fails. If I backup to the C:/ drive then copy it over to the disk it
> works fine but when SQL Server tries to do it, it can't.
> I am simply doing the following:
> BACKUP DATABASE MyDatabase TO DISK = 'E:/backup.dat_bak' WITH INIT
> Anyone know what could be going wrong?

Have LocalSystem account (or account for SQL Server) privileges to access
flash disk?|||bostonpartykid@.yahoo.com (Ray Lavelle) wrote in message news:<d8653140.0309032311.36f02596@.posting.google.com>...
> I have a utility I wrote which can backup/restore my database as well
> as schedule backups. This has always worked pretty well except when I
> try to backup to a USB Flash Disk. When I use one of these the backup
> fails. If I backup to the C:/ drive then copy it over to the disk it
> works fine but when SQL Server tries to do it, it can't.
> I am simply doing the following:
> BACKUP DATABASE MyDatabase TO DISK = 'E:/backup.dat_bak' WITH INIT
> Anyone know what could be going wrong?

You might be seeing this issue:

http://support.microsoft.com/defaul...kb;en-us;281345

Otherwise, can you clarify what you mean by the backup "fails"? Is
there an error message? Presumably the USB drive appears in Windows as
a local drive? And what result do you get if you execute this query:

exec master..xp_cmdshell 'dir e:\'

Simon|||It turned out that the problem was that backing up to a USB disk is a
lot slower so the command timed out. Simply increasing the
commandTimeout solved the problem.

sql@.hayes.ch (Simon Hayes) wrote in message news:<60cd0137.0309040634.7b13ab50@.posting.google.com>...
> bostonpartykid@.yahoo.com (Ray Lavelle) wrote in message news:<d8653140.0309032311.36f02596@.posting.google.com>...
> > I have a utility I wrote which can backup/restore my database as well
> > as schedule backups. This has always worked pretty well except when I
> > try to backup to a USB Flash Disk. When I use one of these the backup
> > fails. If I backup to the C:/ drive then copy it over to the disk it
> > works fine but when SQL Server tries to do it, it can't.
> > I am simply doing the following:
> > BACKUP DATABASE MyDatabase TO DISK = 'E:/backup.dat_bak' WITH INIT
> > Anyone know what could be going wrong?
> You might be seeing this issue:
> http://support.microsoft.com/defaul...kb;en-us;281345
> Otherwise, can you clarify what you mean by the backup "fails"? Is
> there an error message? Presumably the USB drive appears in Windows as
> a local drive? And what result do you get if you execute this query:
> exec master..xp_cmdshell 'dir e:\'
> Simon