Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Friday, March 30, 2012

Relationshiptype in type 2 Slowly Changing Dimensions

Hi,

I've got a cusomer dimension buil on a type 2 slowly changing dimension with following attributes:

customer group

customer name

customer number (business key)

surrogate key

I've got one hierarchie:

customer group -- customer number

and defined a one to many relationship between customergroup and customer.

What I am not sure about:

Can I choose relationshiptype = Rigid for this relation?

When a customer is moved to another customer group, a new record in the dimension table will be added.

Before change

Group A nr. 12345 surr. key 1

after the change, a second record was added

Group A nr. 12345 surr. key 1

Group B nr. 12345 surr. key 2

So the relationship between customer group and customer number is not one to many, but many to many in the dimension table.

So, do i have to define the relation as flexible ?

or is there some misunderstanding......

Keme

Hello. You use surrogate keys so rigid attribute relations will not be a problem. As long as you keep your source key for customer in the cube I cannot see any problems with this approach.

If you have a problem with dynamic attributes in a dimension, that changes frequently, you can build a new dimension table for them. In the AdventureWorks cube and DW you can see a separate dimension for Geography.

People change address so instead of keeping this dynamic relationship in a customer dimension table you make a separate dimension table and a new foreign key in the fact table.

In AdventureWorksDW Geography is related to Customer but I would prefer a Geography foreign key in the fact table. if you use this approach type1, type2 or type3 SCD:s will not be a problem.

Downside: You will not be able to drill down from customer country to a single customer.

Rigid attribute relations will always require a full process of the dimension and the cube when there is a change.

Regards

Thomas Ivarsson

|||

Hi Thomas,

thanks for your reply.

>> You use surrogate keys so rigid attribute relations will not be a problem. As long as you keep your source key for customer in the cube I cannot see any problems with this approach.

My problem is, that in my example the key for the relation customer --> customer group is not unique

Group A nr. 12345 surr. key 1

Group B nr. 12345 surr. key 2

it chould be customergroup customer should be 1:n ; But customer nr. 12345 has two groups in the table.

So referential integrity for the attribute relation is destroyed and if I change ErrorConfiguration, KeyDuplicate from 'Ignore' to 'ReportAndContinue' the dimension fails to process.

The surrogate key is still unique, but it seems that does not help for the relation beween customer and customer group.

I read 'The Microsoft Data Warehouse Toolkit" from the KImball Group and followed the instructions for building the relational DWH with slowly changing dimensions and surrogate keys.

What I'm not sure about ist how to handle relations for the changing attributes ofSCD2 Dimensions.

First choice was to have related all attributes to the dimension key as dimension designer by default does. Worked fine.

Then I read about the importance of attribute relations on performance because of natural hierarchies, so I decided to better declare them. (Type rigid does fail, and I'm not sure about the impact of Type 'flexible' and if it is still a help to performance then)

Your suggestĂ­on with a separate table would be working, but I thought it would be the nice thing about a well built relational DWH that you can put a cube on top by a few clicks ?

|||

OK. So if you build your attribute relation between customer and the customergroup with the surrogate key, this does not work?

The relation between the surrogate customer key and the customergroup must be one to many, from the customergroup level?

It seems to me that you have build this relation on the source customer key?

Have missed some important information.

Regards

Thomas Ivarsson

|||

You are right. I built the relation on the source customer key.

For my example, you are right. In this constellation, the problem is solved when using the surrogate key for the relation.

So, please try this one:

The dimension table has the following attributes:

catgegory -- subcategory -- item--surrogate key

In the source system theres the relation category-subcategory-item. > natural hierarchie with 3 levels

So what i would do in SAS is:

1. Within Attribute surrogate key, I define a relation (one to many) with subcategory

2. Within Subcategory I define a relationship (one to many) with category

The problem would occur, if a subcategory changed to another category. Then the constellation in the dimension table would be:

Category A Subcategory a item 4711 SK 1

Category B Subcategory a item 4711 SK 1

Then I would get the 'key duplicate' problem for 'Subcategory a' again.

It is all a bit theoretical, but the main question to me is:

I used star schema for a relational DWH: The dimension is totally denormalized.

I use surrogate keys for the dimensions and dimensions are implemented as SCD with all attributes type 2.

Now, if I have more than 2 related attributes in a dimensio, I have either to use snowflake design or leave out the relationship ?

Regards,

Keme

|||

Hello. I think that you are on the right track.

If the relation between the subcategory and the category change over time, and you would like to keep history, for this relation, you will have to use surrogate keys here as well. The only option then, from what i know, is to snowflake the dimension.

If you see the upper relation as type1 SCD you can keep the starschema design. Simply do an update in the ETL process.

When you do a significant change like changing relations above the leaf level in a dimension, I think the idea of SCD fails. You will expand the dimension tree continously and make it even harder to analyse data over the time dimension. Categories and subcategories will no longer be the same. It is better, from my experience to treat these changes as SCD I and do a change that erase history.

Kind Regards

Thomas Ivarsson

|||

Hello Thomas,

Thank you.

Think, now it is clear to me.

Regards

Keme

Wednesday, March 28, 2012

Relationship map using CTEs

For instance, if I have the following values in a table
Id ParentId
1 null
2 1
3 1
4 2
5 4
I understand how to traverse this relationship tree using CTE but how would
I build a map where I say Id 1 is related to Id 2, 3, 4, 5... Like so,
Return results
Id RelatedId
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 4
2 5
3 1
3 3
4 1
4 2
4 4
4 5
5 1
5 2
5 4
5 5
Basically, an Id is related to every id that descends from it (directly or
indirectly) and an id is related to every parent link upwards from it.
Is this possible with CTEs?"Arif" <Arif@.discussions.microsoft.com> wrote in message
news:2B66D0F9-7E43-41C1-9B93-6DF147E5EB83@.microsoft.com...
> For instance, if I have the following values in a table
> Id ParentId
> 1 null
> 2 1
> 3 1
> 4 2
> 5 4
>
> I understand how to traverse this relationship tree using CTE but how
> would
> I build a map where I say Id 1 is related to Id 2, 3, 4, 5... Like so,
>
> Return results
> Id RelatedId
> 1 1
> 1 2
> 1 3
> 1 4
> 1 5
> 2 1
> 2 2
> 2 4
> 2 5
> 3 1
> 3 3
> 4 1
> 4 2
> 4 4
> 4 5
> 5 1
> 5 2
> 5 4
> 5 5
>
> Basically, an Id is related to every id that descends from it (directly or
> indirectly) and an id is related to every parent link upwards from it.
> Is this possible with CTEs?
Yes. Here's an example of how to enumerate a transative relation using a
CTE:
Create Table T
(
ID int primary key,
ParentID int references T
)
insert into t(id,parentid)
select 1,null
union all select 2,1
union all select 3,1
union all select 4,2
union all select 5,4
go
with Related(ID, RelatedID, Distance)
as
(
--anchor with reflexive member
select ID, ID, 0 from T
--union in transitively related members
union all
select r.ID, t.ID, r.Distance + 1
from T t join Related r
on t.ParentID = r.RelatedID
)
select * from Related
order by id, RelatedID, Distance
/* results
ID RelatedID Distance
-- -- --
1 1 0
1 2 1
1 3 1
1 4 2
1 5 3
2 2 0
2 4 1
2 5 2
3 3 0
4 4 0
4 5 1
5 5 0
*/
David

relationship between set ansi_defaults and set implicit_transactio

BOL States the following in the SET ANSI_DEFAULTS section:
SQL Server ODBC driver automatically set ANSI_DEFAULTS to ON when
connecting. The driver then set CURSOR_CLOSE_ON_COMMIT and
IMPLICIT_TRANSACTIONS to OFF.
BOL States the following in the SET IMPLICIT_TRANSACTIONS:
When SET ANSI_DEFAULTS is ON, SET IMPLICIT_TRANSACTIONS is enabled.
What does SET IMPLICIT_TRANSACTIONS is enabled mean? If it means SET
IMPLICIT_TRANSACTIONS is ON, is this conflicting with the statment in the SE
T
ANSI_DEFAULTS section. Or the setting ANSI_DEFAULTS affects the setting
IMPLICIT_TRANSACTIONS differently based on the source (driver or sql
statement).ANSI_DEFAULT is just a grouping of other SET options, a way to turn on a num
ber of SET options with
one command. Seems like ODBC first turn on ANSI_DEFAULT and then turn off IM
PLICIT_TRANSACTIONS.
This is doable, "turn on all which are in ANSI_DEFAULT but I don't want IMPL
ICIT_TRANSACTIOPNS so I
turn that off explicitly":
DBCC USEROPTIONS
SET ANSI_DEFAULTS ON
GO
DBCC USEROPTIONS
SET IMPLICIT_TRANSACTIONS OFF
GO
DBCC USEROPTIONS
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Peter" <Peter@.discussions.microsoft.com> wrote in message
news:AF6843DA-18C9-4980-A25E-55D9FAE003E6@.microsoft.com...
> BOL States the following in the SET ANSI_DEFAULTS section:
> SQL Server ODBC driver automatically set ANSI_DEFAULTS to ON when
> connecting. The driver then set CURSOR_CLOSE_ON_COMMIT and
> IMPLICIT_TRANSACTIONS to OFF.
>
> BOL States the following in the SET IMPLICIT_TRANSACTIONS:
> When SET ANSI_DEFAULTS is ON, SET IMPLICIT_TRANSACTIONS is enabled.
>
> What does SET IMPLICIT_TRANSACTIONS is enabled mean? If it means SET
> IMPLICIT_TRANSACTIONS is ON, is this conflicting with the statment in the
SET
> ANSI_DEFAULTS section. Or the setting ANSI_DEFAULTS affects the setting
> IMPLICIT_TRANSACTIONS differently based on the source (driver or sql
> statement).

Monday, March 26, 2012

Relational Design Question

I'm designing a database for a medical research group in a university
medical center that studies organ transplant patients following surgery.
There is no existing database and all data is currently recorded on a
lengthy paper form. The paper form has hundreds of checkboxes as well as
dozens of free-form data entry fields (to indicate medications, dosages, and
comments). This form is filled out immediately after the initial surgery and
then on each subsequent followup appointment. So this same form is filled
out many times for the same patient over a period of years. For your
"visual" on this paper form, just think about any paper form you have had to
fill out for your medical history for any doctor's appointment you've ever
been to; now multiply the number of fields on that form by by 5 or 6 times
and that's what I'm dealing with.
My question is about the data model and table design to implement:
The unique identifier for patients will be the "Patient ID" assigned by the
hospital from their system of record. Not much debate on that.
One important consideration is all those check boxes. Some mean "true or
false" and can ony mean one or the other; while many check boxes
legitimately can mean "null or true or false". So for each appointment,
there will likely be many NULL values to be dealt with. Also, some of the
check boxes are logically grouped into mutually exclusive options.
Historical records from thousands of paper forms collected over the past
several years will be entered into this db once it's up and running.
My initial opinion is to store the information "vertically" and not
"horizontally"... something like this:
CREATE TABLE [Patients] (
[PatientID] [char] (12) NOT NULL ,
[FirstName] [varchar] (30) NOT NULL ,
[LastName] [varchar] (30) NOT NULL,
-- other columns here...
CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
([PatientID]) ON [PRIMARY]
) ON [PRIMARY]
Here's where all the data collected on the paper form would be stored:
CREATE TABLE [PostTransplantData] (
[PatientID] [char] (12) NOT NULL ,
[ApointmentDateTime] [datetime] NOT NULL ,
[FieldID] [int] NOT NULL ,
[FieldValue] [varchar] (100) NULL ,
CONSTRAINT [PK_PostTransplantData] PRIMARY KEY CLUSTERED
([PatientID],[ApointmentDateTime],[Field
ID]) ON [PRIMARY]
) ON [PRIMARY]
... as opposed to storing it "horizontally" with one column in the
PostTransplantData table per checkbox or other field on the paper form.
Doing that would tie the db design to the paper form... something we don't
want to do for obvious reasons.
NOTE TO CELKO: FieldID in this db is used to refer to the Field on the paper
form, as described elsewhere in the database. AFAIK, Columns in the db are
supposed to map to "real things in the real world" and in our case those
"real things" are FIELDs on a paper form. And no, I'm not trying to
duplicate the paper form in the db (thus the proposed tables above).
Thoughts? Opinions? Suggestions?
Thanks!Jeff wrote:
> I'm designing a database for a medical research group in a university
> medical center that studies organ transplant patients following surgery.
> There is no existing database and all data is currently recorded on a
> lengthy paper form. The paper form has hundreds of checkboxes as well as
> dozens of free-form data entry fields (to indicate medications, dosages, a
nd
> comments). This form is filled out immediately after the initial surgery a
nd
> then on each subsequent followup appointment. So this same form is filled
> out many times for the same patient over a period of years. For your
> "visual" on this paper form, just think about any paper form you have had
to
> fill out for your medical history for any doctor's appointment you've ever
> been to; now multiply the number of fields on that form by by 5 or 6 times
> and that's what I'm dealing with.
> My question is about the data model and table design to implement:
> The unique identifier for patients will be the "Patient ID" assigned by th
e
> hospital from their system of record. Not much debate on that.
> One important consideration is all those check boxes. Some mean "true or
> false" and can ony mean one or the other; while many check boxes
> legitimately can mean "null or true or false". So for each appointment,
> there will likely be many NULL values to be dealt with. Also, some of the
> check boxes are logically grouped into mutually exclusive options.
> Historical records from thousands of paper forms collected over the past
> several years will be entered into this db once it's up and running.
> My initial opinion is to store the information "vertically" and not
> "horizontally"... something like this:
> CREATE TABLE [Patients] (
> [PatientID] [char] (12) NOT NULL ,
> [FirstName] [varchar] (30) NOT NULL ,
> [LastName] [varchar] (30) NOT NULL,
> -- other columns here...
> CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
> ([PatientID]) ON [PRIMARY]
> ) ON [PRIMARY]
>
> Here's where all the data collected on the paper form would be stored:
> CREATE TABLE [PostTransplantData] (
> [PatientID] [char] (12) NOT NULL ,
> [ApointmentDateTime] [datetime] NOT NULL ,
> [FieldID] [int] NOT NULL ,
> [FieldValue] [varchar] (100) NULL ,
> CONSTRAINT [PK_PostTransplantData] PRIMARY KEY CLUSTERED
> ([PatientID],[ApointmentDateTime],[Field
ID]) ON [PRIMARY]
> ) ON [PRIMARY]
> ... as opposed to storing it "horizontally" with one column in the
> PostTransplantData table per checkbox or other field on the paper form.
> Doing that would tie the db design to the paper form... something we don't
> want to do for obvious reasons.
> NOTE TO CELKO: FieldID in this db is used to refer to the Field on the pap
er
> form, as described elsewhere in the database. AFAIK, Columns in the db are
> supposed to map to "real things in the real world" and in our case those
> "real things" are FIELDs on a paper form. And no, I'm not trying to
> duplicate the paper form in the db (thus the proposed tables above).
> Thoughts? Opinions? Suggestions?
> Thanks!
I don't know your business but my first reaction would be that check
boxes on a form are not "real" data they are a means of COLLECTING
data. I'd say you should model the real information represented on the
forms and I suspect your design won't do that well. For example if some
questions are mutually exclusive (like a series of selections
representing age ranges or different possible outcomes) it would
probably be more effective to model them in a single column rather than
multiple columns.
I also don't like the sound of:

> many check boxes
> legitimately can mean "null or true or false"
Even if that is so, that's no reason to use a nullable column to
represent those values in the database. In fact I'd say that if "null"
is a legitimate response then you certainly should NOT represent that
with a null in the database. A null in this case presumably could mean
"unanswered" or "not applicable" or "don't know" - use a proper value
or values to represent that fact.
Hope this helps.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||David Portas wrote:
> For example if some
> questions are mutually exclusive (like a series of selections
> representing age ranges or different possible outcomes) it would
> probably be more effective to model them in a single column rather than
> multiple columns.
>
Given your example my comment doesn't really explain what I meant to
say. I mean that a more effective design would be to represent such an
attribute as a single value in its own column rather than as a set of
values in a column or as a set of columns.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Most of your words make good sense. One row per value, makes sense. Field
= position on paper, ok, but not Field = Questionaire. Also,
AppointmentDateTime probably shouldn't be on the PostTransplantData since
the same value will be true for each. I might also be a bit less likely to
have a table that is so specifically named. You might find that a
PreTransplant review might be needed sometime, and the same format might be
usable.
What I might have is two tables to set up the questionaire (I would use
surrogate keys as my actual keys, but to each their own)
Questionaire
===========
QuesionaireName (pk)
Other information, like description
QuestionaireQuestion <-- you might even break this up into question and
questionaire question to allow questions to be used by multiple
questionaires in the future)
=============
QuestionaireName
Question
pk (QuestionaireName,Question)
Answer Format (checkbox, freeform, etc)
Answer Required
Maybe some form field information if you want to build the visual report
from the information)
Possibly some interpretational information, like for printing
Possibly some ties to information to help the doctor with drug or other
disease interaction
This will give you the data to interpret the answers. Then the other tables:
Patient
=====
PatientId
Name Columns
Etc
Appointment
==========
PatientId
DateTime
AppointmentQuestionaireAnswer
=======================
AppointmentKey (whatever is chosen)
QuestionKey
Answer (probably a variant, but you could just textualize it.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Jeff" <A@.B.COM> wrote in message
news:eSLxP$4HGHA.3056@.TK2MSFTNGP09.phx.gbl...
> I'm designing a database for a medical research group in a university
> medical center that studies organ transplant patients following surgery.
> There is no existing database and all data is currently recorded on a
> lengthy paper form. The paper form has hundreds of checkboxes as well as
> dozens of free-form data entry fields (to indicate medications, dosages,
> and comments). This form is filled out immediately after the initial
> surgery and then on each subsequent followup appointment. So this same
> form is filled out many times for the same patient over a period of years.
> For your "visual" on this paper form, just think about any paper form you
> have had to fill out for your medical history for any doctor's appointment
> you've ever been to; now multiply the number of fields on that form by by
> 5 or 6 times and that's what I'm dealing with.
> My question is about the data model and table design to implement:
> The unique identifier for patients will be the "Patient ID" assigned by
> the hospital from their system of record. Not much debate on that.
> One important consideration is all those check boxes. Some mean "true or
> false" and can ony mean one or the other; while many check boxes
> legitimately can mean "null or true or false". So for each appointment,
> there will likely be many NULL values to be dealt with. Also, some of the
> check boxes are logically grouped into mutually exclusive options.
> Historical records from thousands of paper forms collected over the past
> several years will be entered into this db once it's up and running.
> My initial opinion is to store the information "vertically" and not
> "horizontally"... something like this:
> CREATE TABLE [Patients] (
> [PatientID] [char] (12) NOT NULL ,
> [FirstName] [varchar] (30) NOT NULL ,
> [LastName] [varchar] (30) NOT NULL,
> -- other columns here...
> CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
> ([PatientID]) ON [PRIMARY]
> ) ON [PRIMARY]
>
> Here's where all the data collected on the paper form would be stored:
> CREATE TABLE [PostTransplantData] (
> [PatientID] [char] (12) NOT NULL ,
> [ApointmentDateTime] [datetime] NOT NULL ,
> [FieldID] [int] NOT NULL ,
> [FieldValue] [varchar] (100) NULL ,
> CONSTRAINT [PK_PostTransplantData] PRIMARY KEY CLUSTERED
> ([PatientID],[ApointmentDateTime],[Field
ID]) ON [PRIMARY]
> ) ON [PRIMARY]
> ... as opposed to storing it "horizontally" with one column in the
> PostTransplantData table per checkbox or other field on the paper form.
> Doing that would tie the db design to the paper form... something we don't
> want to do for obvious reasons.
> NOTE TO CELKO: FieldID in this db is used to refer to the Field on the
> paper form, as described elsewhere in the database. AFAIK, Columns in the
> db are supposed to map to "real things in the real world" and in our case
> those "real things" are FIELDs on a paper form. And no, I'm not trying to
> duplicate the paper form in the db (thus the proposed tables above).
> Thoughts? Opinions? Suggestions?
> Thanks!
>
>|||RE:
<< ... a more effective design would be to represent such an attribute as a
single value in its own column rather than as a set of values in a column or
as a set of columns >>
So are you saying that basically I should do something like this:
1. Create a bunch of tables that correctly model the "things about the
patient" that are being collected on the paper forms.
2. Then for the things that can be one of {null, true, false} (i.e.,
collected via check boxes on paper form) there is a column "per thing" that
stores just that: NULL, 1 (true), 0 (false).
Yes? More or less?
Thanks for your helpful feedback.
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1137963709.394009.142820@.g44g2000cwa.googlegroups.com...
> David Portas wrote:
> Given your example my comment doesn't really explain what I meant to
> say. I mean that a more effective design would be to represent such an
> attribute as a single value in its own column rather than as a set of
> values in a column or as a set of columns.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>|||RE:
<< A null in this case presumably could mean "unanswered" or "not
applicable" or "don't know" - use a proper value or values to represent that
fact.>>
You are correct.
So to make sure I understand, I would NOT store a NULL value then? I'd store
some [perhaps integer] value that means "unanswered" or "not applicable",
etc?
For some reason I thought NULL was the "catch-all" value to be used to
recommend such things.
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1137962776.499876.6020@.g43g2000cwa.googlegroups.com...
> Jeff wrote:
> I don't know your business but my first reaction would be that check
> boxes on a form are not "real" data they are a means of COLLECTING
> data. I'd say you should model the real information represented on the
> forms and I suspect your design won't do that well. For example if some
> questions are mutually exclusive (like a series of selections
> representing age ranges or different possible outcomes) it would
> probably be more effective to model them in a single column rather than
> multiple columns.
> I also don't like the sound of:
>
> Even if that is so, that's no reason to use a nullable column to
> represent those values in the database. In fact I'd say that if "null"
> is a legitimate response then you certainly should NOT represent that
> with a null in the database. A null in this case presumably could mean
> "unanswered" or "not applicable" or "don't know" - use a proper value
> or values to represent that fact.
> Hope this helps.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>|||Jeff wrote:
> RE:
> << ... a more effective design would be to represent such an attribute as
a
> single value in its own column rather than as a set of values in a column
or
> as a set of columns >>
> So are you saying that basically I should do something like this:
> 1. Create a bunch of tables that correctly model the "things about the
> patient" that are being collected on the paper forms.
> 2. Then for the things that can be one of {null, true, false} (i.e.,
> collected via check boxes on paper form) there is a column "per thing" tha
t
> stores just that: NULL, 1 (true), 0 (false).
> Yes? More or less?
> Thanks for your helpful feedback.
>
1. Yes.
2. I don't use 1 and 0 to represent TRUE and FALSE if I can avoid it.
What is the *fact* that is true or false? That I am male? Or that I'm
over 30 years old? So how about using columns for Gender and Age with
proper codes or values instead of 1 or 0. If I must represent TRUE and
FALSE then I'll use a character code so that I can easily add new
statuses if the need arises. Avoid BIT. The BIT type has so many
peculiarities that it's more trouble that it's worth IMO.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Jeff wrote:
> RE:
> << A null in this case presumably could mean "unanswered" or "not
> applicable" or "don't know" - use a proper value or values to represent
> that fact.>>
> You are correct.
> So to make sure I understand, I would NOT store a NULL value then? I'd
> store some [perhaps integer] value that means "unanswered" or "not
> applicable", etc?
> For some reason I thought NULL was the "catch-all" value to be used to
> recommend such things.
>
Yes and no. Opinions about NULLs differ - in fact it's a highly
controversial topic. The problem is that NULLs aren't like real values. They
are treated differently in SQL logic. That means the more NULLs you have the
more complex your code ultimately becomes and likely the more mistakes you
will make. For this reason sensible designers use NULLs infrequently and
many avoid them altogether.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||RE:
<< For this reason sensible designers use NULLs infrequently and many avoid
them altogether.>>
Yes, I've been aware that NULLs are both controversial and I've minimized
their use as a matter of course. This project, however, appears like it will
frequently have a *majority* of entries [collected during any given patient
appointment] "not applicable" or "unknown" or "legitimately blank".
So, what would a sensible designer do to represent the values "not
applicable" or "unknown" or "legitimately blank". Would an integer column be
created with values coded to the various meanings? e.g., 0=not applicable,
1=unknown, 2=legitimately blank, and then other values assigned to true,
false, yes, no, etc?
Thanks again for your helpful feedback.
-Jeff
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:euX2kK6HGHA.2696@.TK2MSFTNGP14.phx.gbl...
> Jeff wrote:
> Yes and no. Opinions about NULLs differ - in fact it's a highly
> controversial topic. The problem is that NULLs aren't like real values.
> They are treated differently in SQL logic. That means the more NULLs you
> have the more complex your code ultimately becomes and likely the more
> mistakes you will make. For this reason sensible designers use NULLs
> infrequently and many avoid them altogether.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>|||Jeff wrote:
> RE:
> << A null in this case presumably could mean "unanswered" or "not
> applicable" or "don't know" - use a proper value or values to represent th
at
> fact.>>
> You are correct.
> So to make sure I understand, I would NOT store a NULL value then? I'd sto
re
> some [perhaps integer] value that means "unanswered" or "not applicable",
> etc?
> For some reason I thought NULL was the "catch-all" value to be used to
> recommend such things.
>
Yes and no. Opinions about NULLs differ - in fact it's a highly
controversial topic. The problem is that NULLs aren't like real values.
They are treated differently in SQL logic. That means the more NULLs
you have the more complex your code ultimately becomes and likely the
more mistakes you will make. For this reason sensible designers use
NULLs infrequently and many avoid them altogether.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

Relational Database design problem

Hi,

I have a very important question about the database design. Suppose that I have a table named as tblPerson with the following Fields.

tblPerson:
--------
PersonID
PersonName

And I have a another table that has the Person Credit card Information:

tblPersonCreditCard:
---------

CreditCardID
PersonID
CreditCardTypeID

And Another table which contains the type of creditcards:

tblCreditCardsType:
----------

CreditCardTypeID
CardName

NOTE: Suppose CreditCardTypeID 1 = "MasterCard", 2 = "Visa" , 3 = "platinum"

Now if a person suppose "john" has three credit cards then it will be stored as.

tblPersonCreditCard:
---------

CreditCardID PersonID CreditCardTypeID
1 1 1
2 1 2
3 1 3

Each if the number belong to one Field.

Which means that "john" has three credit cards

Now as u see that in tblPersonCreditCard john's id, which is 1 is repeating 3 time. how can I design a database in which the id does not repeat. I have heard that this can be done by using the bitwise operator but HOW.

thanks in advance,

AzamI don't see a problem with each record in tblPersonCreditCard including a foreign key to the credit card's owner. Is there some problem you're having with doing so?|||No i am not having any problem. But I just wanted to know that if there a better way of doing the same thing.|||There is no reason to do what you are attempting to do. To create a many-to-one relationship, you need to have a foreign key which will potentially repeat in the child table.|||I have heard that you can use some sort of the bit wise operator to store all the relationship of the person in a single field. I have no idea how ??|||I think you mean "bitmask", actually. Here'san article, if you're really interested.

Friday, March 23, 2012

Related Tables: Help Needed With JOIN Query

Hi Group,

My apologies for the lengthy post, but here goes...

I have the following tables:

TABLE Vehicles
(
[ID] nvarchar(5),
[Make] nvarchar(20),
[Model] nvarchar(20),
)

TABLE [Vehicle Status]
(
[ID] int, /* this is an auto-incrementing field*/
[Vehicle ID] nvarchar(5), /* foriegn key, references Vehicles.[ID] */
[Status] nvarchar(20),
[Status Date] datetime
)

Here's my problem...

I have the following data in my [Vehicles] and [Vehicle Status] tables:

[ID] [Make] [Model]
-------
H80 Nissan Skyline
H86 Toyota Aristo

[ID] [Vehicle ID] [Status] [Status Date]
------------
1 H80 OK 2006-10-01
2 H80 Damage 2006-10-05
3 H86 OK 2006-10-13
4 H86 Dent 2006-10-15
5 H86 Scratched 2006-10-16

I need a query that will join the two tables so that the most recent
status of each vehicle can be determined. I've gotten as far as:

SELECT Vehicle.[ID], Make, Model, [Status], [Status Date] FROM
[Vehicles] INNER JOIN [Vehicle Status] ON [Vehicles].[ID] = [Vehicle
Status].[Vehicle ID]

Of course this produces the following results:

[ID] [Make] [Model] [Status] [Status Date]
--------------
H80 Nissan Skyline OK 2006-10-01
H80 Nissan Skyline Damage 2006-10-05
H86 Toyota Aristo OK 2006-10-13
H86 Toyota Aristo Dent 2006-10-15
H86 Toyota Aristo Scratched 2006-10-16

How do I filter these results so that I get only the MOST RECENT vehicle
status?

i.e:

[ID] [Make] [Model] [Status] [Status Date]
--------------
H80 Nissan Skyline Damage 2006-10-05
H86 Toyota Aristo Scratched 2006-10-16

Thanks in advance,
Rommel the iCeMAn

*** Sent via Developersdex http://www.developersdex.com ***SELECT v.[ID], Make, Model, [Status], [Status Date]
FROM
[Vehicles] v INNER JOIN [Vehicle Status] vs ON v.[ID] = vs.[Vehicle ID]
and vs.[Status Date] = (select max(vs2.[Status Date]) from [Vehicle
Status] vs2 where vs2.[Vehicle ID] = vs.[Vehicle ID])

www.nigelrivett.net
*** Sent via Developersdex http://www.developersdex.com ***sql

Reinstalling sql 2005

please ... really need some guidance...
I have removed the old and reinstalled SQL server 2005 standard...
Getting the following message:
Your OS doesn't meet Service pack levels requirements
for this SQL server releaseSo I installed Microsoft SQL Server 2005 Service Pack 1 (SP1)
Getting the following message: This machine does not have a product that matches this installation package.

I have Windows XP Professional 2002 32-bit (Dell), Windows XP Service Pack 2, IIS, NET Framework 2.0., 13GB , processor intel 1,5 GHz, 256MB RAM

1. What is the SKU of SQL Server 2005 are you installing? On Windows XP SP2, SQL Server Enterprise edition cannot be installed.

2. SP1 cannot be installed directly except SQL Express, which is rebuilt in SP1. SP1 should be applied after RTM is installed.

|||

I posted this question to your other thread, but I'll post it here as well to try to get you going again. The error you are getting is a result of trying to instal a version of SQL 2005 on an OS that does not contain the appropriate OS SP, not a SQL service pack. If you can supply us with the exact OS & service pack level and the version of SQL you are trying to install, we can help out.

I'm a little confused on your OS. Can you do start -> Run and type in "winver". This will tell you your OS and SP level. Can you let me know what that shows? That way we'll be able to figure out what you need to install to get going.

Thanks,
Sam

|||Thank you so much! Actually I need SQL standard or develope, but it didn't work yet. So the trial version will not work, or?
Windows XP Professional
Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519: Service Pack 2)
(Windows XP Professional version 2002 32-bit, Windows XP
Service Pack 2, IIS, .NET Framework 2.0., 13GB free space,
processor intel 1,5 GHz, 256MB RAM)

Wednesday, March 21, 2012

Reinstalling database devices

Hello,
I am experiencing the following problem: The SAs were
upgrading apps on the server and the server literally ate
itself. Thus requiring a reinstall of SQL Server.
However, the data and log files are still in tact on the
box. The backup tapes are empty and I am trying to
recreate the devices and databases using the existing
files. Is that possible? If yes, how would I proceed?
Thanks.You can hopefully attach the database file using sp_attach_db.
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver
"Albert H. Offer" <ahoffer@.magellanhealth.com> wrote in message
news:0ebe01c38f34$df72f430$a101280a@.phx.gbl...
> Hello,
> I am experiencing the following problem: The SAs were
> upgrading apps on the server and the server literally ate
> itself. Thus requiring a reinstall of SQL Server.
> However, the data and log files are still in tact on the
> box. The backup tapes are empty and I am trying to
> recreate the devices and databases using the existing
> files. Is that possible? If yes, how would I proceed?
> Thanks.|||Hi Albert, if the old directories are still valid, replacing the new master
with old one will be enough: it will point to your data files.
Another option (if the old master is not available) would be using
sp_attach_db to fill the new master with the information about your old db
data files.
The first option is better because the old master will be on-line with all
of your configuration options, logins, etc.
Syntax about sp_attach_db is bellow (from books on line):
sp_attach_db
Attaches a database to a server.
Syntax
sp_attach_db [ @.dbname = ] 'dbname'
, [ @.filename1 = ] 'filename_n' [ ,...16 ]
Arguments
[@.dbname =] 'dbname'
Is the name of the database to be attached to the server. The name must be
unique. dbname is sysname, with a default of NULL.
[@.filename1 =] 'filename_n'
Is the physical name, including path, of a database file. filename_n is
nvarchar(260), with a default of NULL. There can be up to 16 file names
specified. The parameter names start at @.filename1 and increment to
@.filename16. The file name list must include at least the primary file,
which contains the system tables that point to other files in the database.
The list must also include any files that were moved after the database was
detached.
Return Code Values
0 (success) or 1 (failure)
Result Sets
None
Remarks
sp_attach_db should only be executed on databases that were previously
detached from the database server using an explicit sp_detach_db operation.
If more than 16 files must be specified, use CREATE DATABASE with the FOR
ATTACH clause.
If you attach a database to a server other than the server from which the
database was detached, and the detached database was enabled for
replication, you should run sp_removedbreplication to remove replication
from the database.
Permissions
Only members of the sysadmin and dbcreator fixed server roles can execute
this procedure.
Examples
This example attaches two files from pubs to the current server.
EXEC sp_attach_db @.dbname = N'pubs',
@.filename1 = N'c:\Program Files\Microsoft SQL
Server\MSSQL\Data\pubs.mdf',
@.filename2 = N'c:\Program Files\Microsoft SQL
Server\MSSQL\Data\pubs_log.ldf'
hth,
Roberto de Souza Santos.
"Albert H. Offer" <ahoffer@.magellanhealth.com> wrote in message
news:0ebe01c38f34$df72f430$a101280a@.phx.gbl...
> Hello,
> I am experiencing the following problem: The SAs were
> upgrading apps on the server and the server literally ate
> itself. Thus requiring a reinstall of SQL Server.
> However, the data and log files are still in tact on the
> box. The backup tapes are empty and I am trying to
> recreate the devices and databases using the existing
> files. Is that possible? If yes, how would I proceed?
> Thanks.|||Thanks Tibor. I forgot to mention that the box is running SQL Server
6.5.. The backup tapes are no good, so I don't have a good backup of
Master.
Albert H. Offer
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Then you need to use DISK REINIT and DISK REFIT. Make sure you read all you can find about these
commands. It is not even closely as easy as in 7.0 or 2000 as you need to get the database fragments
right with DISK REINIT.
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver
"Albert Offer" <ahoffer@.magellanhealth.com> wrote in message
news:eFLcGN0jDHA.1096@.TK2MSFTNGP11.phx.gbl...
> Thanks Tibor. I forgot to mention that the box is running SQL Server
> 6.5.. The backup tapes are no good, so I don't have a good backup of
> Master.
> Albert H. Offer
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Reinstall ODBC Components

I'm getting the following error on my XP machine:
The ODBC resource DLL c:\windows\system32\odbcint.dll is a different version
than the ODBC setup dll c:\windows\system32\odbccp32.dll reinstall the ODBC
components to ensure proper operation.
I've reinstalled SQL 7.0 several times, how do I reinstall the ODBC
components?
Thank youReinstall MDAC. Reinstalling SQL Server 7 won't update MDAC
as XP is on a higher version. You can also check your
current MDAC installation with component checker
You can find the MDAC downloads and component checker at:
http://msdn.microsoft.com/data/mdac/default.aspx
-Sue
On Wed, 10 Nov 2004 16:24:01 -0800, "Michelle"
<Michelle@.discussions.microsoft.com> wrote:

>I'm getting the following error on my XP machine:
>The ODBC resource DLL c:\windows\system32\odbcint.dll is a different versio
n
>than the ODBC setup dll c:\windows\system32\odbccp32.dll reinstall the ODBC
>components to ensure proper operation.
>I've reinstalled SQL 7.0 several times, how do I reinstall the ODBC
>components?
>Thank you

Reinstall ODBC Components

I'm getting the following error on my XP machine:
The ODBC resource DLL c:\windows\system32\odbcint.dll is a different version
than the ODBC setup dll c:\windows\system32\odbccp32.dll reinstall the ODBC
components to ensure proper operation.
I've reinstalled SQL 7.0 several times, how do I reinstall the ODBC
components?
Thank you
Reinstall MDAC. Reinstalling SQL Server 7 won't update MDAC
as XP is on a higher version. You can also check your
current MDAC installation with component checker
You can find the MDAC downloads and component checker at:
http://msdn.microsoft.com/data/mdac/default.aspx
-Sue
On Wed, 10 Nov 2004 16:24:01 -0800, "Michelle"
<Michelle@.discussions.microsoft.com> wrote:

>I'm getting the following error on my XP machine:
>The ODBC resource DLL c:\windows\system32\odbcint.dll is a different version
>than the ODBC setup dll c:\windows\system32\odbccp32.dll reinstall the ODBC
>components to ensure proper operation.
>I've reinstalled SQL 7.0 several times, how do I reinstall the ODBC
>components?
>Thank you

Monday, March 12, 2012

Reindexing tables with computed columns

I need to reindex a table with a computed column. The column is not
included in any indexes, but when I run the DBCC it crashes with the
following error:
DBCC failed because the following SET options have incorrect settings:
'QUOTED_IDENTIFIER'.
Any ideas on how I can reindex these tables'
Thanks!
Richard
*** Sent via Developersdex http://www.developersdex.com ***Richard,
Sounds like the QUOTED_IDENTIFIER option needs to be ON.
Try the last section of this link:
Creating Indexes on Computed Columns
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_05_8os3.asp
HTH
Jerry
"Richard" <nospam@.devdex.com> wrote in message
news:%23Qes6HM2FHA.460@.TK2MSFTNGP15.phx.gbl...
>I need to reindex a table with a computed column. The column is not
> included in any indexes, but when I run the DBCC it crashes with the
> following error:
> DBCC failed because the following SET options have incorrect settings:
> 'QUOTED_IDENTIFIER'.
> Any ideas on how I can reindex these tables'
> Thanks!
> Richard
>
> *** Sent via Developersdex http://www.developersdex.com ***|||If you're using a non-named instance and are running SP4, you can use
a -supportcomputedcolumn parameter in the first step of the job. If you're
using < SP4 or a named instance, you'll have to create a separate job to
execute the integrity/optimizations. See
http://support.microsoft.com/default.aspx?scid=kb;en-us;902388
I had this trouble in a Sharepoint database. I created a separate job with
two steps, one for integrity checks and one for reorg on all tables. This
KB will give you the script to reorg all tables
http://support.microsoft.com/kb/301292/
HTH
--Lori
"Richard" <nospam@.devdex.com> wrote in message
news:%23Qes6HM2FHA.460@.TK2MSFTNGP15.phx.gbl...
>I need to reindex a table with a computed column. The column is not
> included in any indexes, but when I run the DBCC it crashes with the
> following error:
> DBCC failed because the following SET options have incorrect settings:
> 'QUOTED_IDENTIFIER'.
> Any ideas on how I can reindex these tables'
> Thanks!
> Richard
>
> *** Sent via Developersdex http://www.developersdex.com ***|||Note that the scripts reorgs whether the index is fragmented or not (just as maint wiz does). If you
only want to reorg if there is any fragmentation in the first place, you should use the sample code
provided in Books Online, DBCC SHOWCONTIG.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Lori Clark" <lclark@.dbadvisor.com> wrote in message news:eCYr0NM2FHA.3864@.TK2MSFTNGP12.phx.gbl...
> If you're using a non-named instance and are running SP4, you can use a -supportcomputedcolumn
> parameter in the first step of the job. If you're using < SP4 or a named instance, you'll have to
> create a separate job to execute the integrity/optimizations. See
> http://support.microsoft.com/default.aspx?scid=kb;en-us;902388
> I had this trouble in a Sharepoint database. I created a separate job with two steps, one for
> integrity checks and one for reorg on all tables. This KB will give you the script to reorg all
> tables
> http://support.microsoft.com/kb/301292/
>
> HTH
> --Lori
> "Richard" <nospam@.devdex.com> wrote in message news:%23Qes6HM2FHA.460@.TK2MSFTNGP15.phx.gbl...
>>I need to reindex a table with a computed column. The column is not
>> included in any indexes, but when I run the DBCC it crashes with the
>> following error:
>> DBCC failed because the following SET options have incorrect settings:
>> 'QUOTED_IDENTIFIER'.
>> Any ideas on how I can reindex these tables'
>> Thanks!
>> Richard
>>
>> *** Sent via Developersdex http://www.developersdex.com ***
>

Wednesday, March 7, 2012

Registry for SQL Server Express Instance

I notice that the following registries:
HKLM\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL.2\MSSQLServer\SuperSocketNeLib
HKLM\SOFTWARE\Microsoft\Microsoft SQL
Server\SQLEXPRESS\MSSQLServer\SuperSocke
tNeLib
They seem to be for the same instance. But the first one has very detail
information which match what you will see the SQL Server Configuration
Manager. What is the purpose for having 2 registry for the same instance?Did you make sure that this is for the same instance ? I think this is from
another instance running on your computer. Do you only have SQL Server
Express installed or any other instances running ? Did you try to change a
value in the supersocket area, like the listened port to see if it will be
also reflected in the other area ? Also make sure if the TCP settings do not
differ, because a port can only be aquired by ONE service at a time.
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--
"Peter" <Peter@.discussions.microsoft.com> wrote in message
news:02B46A81-22E7-4DAA-9FC1-7FA978C027FE@.microsoft.com...
>I notice that the following registries:
> HKLM\SOFTWARE\Microsoft\Microsoft SQL
> Server\MSSQL.2\MSSQLServer\SuperSocketNeLib
> HKLM\SOFTWARE\Microsoft\Microsoft SQL
> Server\SQLEXPRESS\MSSQLServer\SuperSocke
tNeLib
> They seem to be for the same instance. But the first one has very detail
> information which match what you will see the SQL Server Configuration
> Manager. What is the purpose for having 2 registry for the same
> instance?
>

Saturday, February 25, 2012

registering MSDE 2000 FROM SQL 2000

Hi There,

I have install msde in one computer and try to register from my sql server, the following error message is coming.

A connection could not be established to Cal-itimilsina (computer in which MSDE IS INSTALLED)

RESON: SQL SERVER DOES NOT EXIST OR ACCESS DENIED

CONNECTIONOPEN(CONNECT())

====

BUT THE MSDE IS RUNNING IN THE CLIENT MACHINE. Could any one please help me

Thanks.

Indra.Check this (http://www.microsoft.com/sql/msde/productinfo/features.asp) site, but in short, - Named Pipes is not supported on MSDE. You need to create an alias on your server for MSDE instance using TCP/IP protocol, and specify the alias during server registration in EM. You can also use the IP address for registration.|||Thanks, i will have a check now.|||Hi,

I setup alias with TCP/IP and try to connect with alias name as well with tcp/ip, but same error message is comming. by the way what cold be my instance, i just install msde with setup.exe from command prompt.

thanks for help|||Type "OSQL -L" in command window.|||Originally posted by rdjabarov
Type "OSQL -L" in command window.

it display the name of the sql server available inthe network.