Showing posts with label practice. Show all posts
Showing posts with label practice. Show all posts

Tuesday, March 27, 2012

Are Bit Flags Bad?

Is the process of using integer data types to represent multiple values via the use of bit flags bad practice? It seems to go against the rules of normalization in a single field can represent multiple values. On the other hand that since these values can be tested for via bitwise operations, that it's not entirely bad.

Any insight would be appreciated.

ThanksI've used integers to store multiple bit states on occasion and found it very usefull.

For instance, you can have multiple boolean security states, and if you think of them as separate boolean values then separate bit fields would seem appropriate. But is you think of them as a single value describing the overall state of the security setting, then you aren't really violating any principles by storing them as a single field.

At a practical level, SQL Server will combine up to eight bit fields and store them internally as a single byte anyway.

Normalization is good practice because it leads to efficient and functional design. But if you avoid an instance where violating it would actually improve an application, then you are letting the cart lead the horse. Normalization is principle, not dogma.|||there is a multitude of examples where M$ itself used...smallint...as a datatype for this type of scenarios. i think int would be an overkill, while following the trend would save you storage space while doing the job.

Sunday, February 19, 2012

appending data to a text column

Hello everyone, I'm a newbie so have some mercy please. Please feel free to
make some best practice suggestions. Here we go, I am importing data into a
table within my database. I'll use some DDL for clarity.
Create table ImportTable
(ImportId int Not Null,
ImportLog text (10000)
)
Create table ExistingTable
(Existingid int Not Null,
Existinglog text (10000)
)
When the data is imported I would like to check if the ImportId column in
ImportTable has a match in ExistingId column within ExistingTable, is so I
would like to APPEND the data from ImportLog to ExistingLog
This is a shortened version of the actual table but its give you guys a
general feel for what I am trying to accomplish. Thanks in advance for any
assistance.
kw_uh97I think this does the job, you need the where condition if it's possible
to have a null entry in the importlog column, for some reason trying to
append null to existingtext converts it to null too:
update existingtable
set existingtext = existingtext + importlog
from existingtable inner join importtable on existingid = importid
where importlog is not null
*** Sent via Developersdex http://www.examnotes.net ***|||Anthony
Sorry for the delay and thanks for the query it works just fine I will
implement this ASAP.
Thanks, Again
kw_uh97
"Anthony Brown" wrote:

> I think this does the job, you need the where condition if it's possible
> to have a null entry in the importlog column, for some reason trying to
> append null to existingtext converts it to null too:
>
> update existingtable
> set existingtext = existingtext + importlog
> from existingtable inner join importtable on existingid = importid
> where importlog is not null
>
> *** Sent via Developersdex http://www.examnotes.net ***
>