Showing posts with label objects. Show all posts
Showing posts with label objects. Show all posts

Sunday, March 11, 2012

Database Diagrams

TITLE: Microsoft SQL Server Management Studio

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.


BUTTONS:

OK

I don't know what is the meaning of the above message, which I get when I 'right click' the Database Diagrams node of the Northwind database. Every thing seems OK, since I am the owner of this database.

I am using the trial version of MS SQL Server 2005.

Hi there,

Check the database compatability level for your database. To do this:

1) Right click on the desired database and select "Properties" from the context menu that appears

2) The "Database Properties" dialog box will appear on your screen. There will be an item on the left hand side of the dialog called "Options". Click on this.

3) The "Database Properties" dialog will change its appearance. There should be an entry in the dialog called "Compatability Level".

Now, from my experience, if the database compatability level is set to anything other than "SQL Server 2005 (90)" then diagramming won't work. You need to change the compatability level to "SQL Server 2005 (90)" if it is not currently set to this.

If that was your problem then after changing the compatability level you should be able to create database diagrams.

Also, while you have the "Database Properties" dialog open, it wouldn't hurt just to check that the owner is valid (if you have not already done so). You can check and edit the database owner by clicking on the "Files" item on the left hand side of the "Database Properties" dialog.

Hope that helps a bit, but sorry if it doesn't
|||

Thanks a lot for your reply

But unfortunately it did not work

I am using Windows Authentication when I log in. And when I click Files in the Database properties windows I find the owner is the same as the log in user.

|||did you create your database with detach/attach?|||

I did not create it

I do not remember, either I imported the database, or it came with the engine.

|||

you might want to eliminate the issue from your local instance by creating a new dummy database. If you have no problem with the new database, the issue might be caused by the source database you got.

I have noticed a similar issue after I shared my database in another machine.

|||

Nate -

Thanks for this post! That worked perfectly for me.

Regards,

Tim

|||

If there is no issue with a fresh database locally, the issue could be likely caused by credential inherited from external database when attached. I found out the similar issue in this scenario and resolved by doing the following,

Alter authorization on database::issue_database_name_here to [domain\user]

Just share my experience.

|||

Sorry, I was offline for few days.

Thank you for your replies. I'll try your solution.

Somebody suggested the following solution to me:

Use Northwind
EXEC sp_helpdb Northwind
EXEC Sp_ChangeDBOwner 'sa'
EXEC sp_helpdb Northwind

I don't have enough experience with SQL Server. So I wish to get your views about the above solution.

Thursday, March 8, 2012

Database Diagrams

TITLE: Microsoft SQL Server Management Studio

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.


BUTTONS:

OK

I don't know what is the meaning of the above message, which I get when I 'right click' the Database Diagrams node of the Northwind database. Every thing seems OK, since I am the owner of this database.

I am using the trial version of MS SQL Server 2005.

Hi there,

Check the database compatability level for your database. To do this:

1) Right click on the desired database and select "Properties" from the context menu that appears

2) The "Database Properties" dialog box will appear on your screen. There will be an item on the left hand side of the dialog called "Options". Click on this.

3) The "Database Properties" dialog will change its appearance. There should be an entry in the dialog called "Compatability Level".

Now, from my experience, if the database compatability level is set to anything other than "SQL Server 2005 (90)" then diagramming won't work. You need to change the compatability level to "SQL Server 2005 (90)" if it is not currently set to this.

If that was your problem then after changing the compatability level you should be able to create database diagrams.

Also, while you have the "Database Properties" dialog open, it wouldn't hurt just to check that the owner is valid (if you have not already done so). You can check and edit the database owner by clicking on the "Files" item on the left hand side of the "Database Properties" dialog.

Hope that helps a bit, but sorry if it doesn't
|||

Thanks a lot for your reply

But unfortunately it did not work

I am using Windows Authentication when I log in. And when I click Files in the Database properties windows I find the owner is the same as the log in user.

|||did you create your database with detach/attach?|||

I did not create it

I do not remember, either I imported the database, or it came with the engine.

|||

you might want to eliminate the issue from your local instance by creating a new dummy database. If you have no problem with the new database, the issue might be caused by the source database you got.

I have noticed a similar issue after I shared my database in another machine.

|||

Nate -

Thanks for this post! That worked perfectly for me.

Regards,

Tim

|||

If there is no issue with a fresh database locally, the issue could be likely caused by credential inherited from external database when attached. I found out the similar issue in this scenario and resolved by doing the following,

Alter authorization on database::issue_database_name_here to [domain\user]

Just share my experience.

|||

Sorry, I was offline for few days.

Thank you for your replies. I'll try your solution.

Somebody suggested the following solution to me:

Use Northwind
EXEC sp_helpdb Northwind
EXEC Sp_ChangeDBOwner 'sa'
EXEC sp_helpdb Northwind

I don't have enough experience with SQL Server. So I wish to get your views about the above solution.

Database diagram support objects cannot... Attaching sql 2000 db to sql server 2005

Hello,

I've seen threads concerning this problem. I have followed the prescribed steps to fix the problem. I've set the db owner to sa, I've set compatibility to 2005. Still I can't get the diagram to function.

Can anyone out there help me?

Thanks, Bill

Hello Bill -

Can you describe your problem a little more? Are you saying that you have a 2K database that you've attached/restored/transported to 2K5 and you can't create a database diagram on it?

Thanks -

Buck Woody

Database diagram support objects cannot... Attaching sql 2000 db to sql server 2005

Hello,

I've seen threads concerning this problem. I have followed the prescribed steps to fix the problem. I've set the db owner to sa, I've set compatibility to 2005. Still I can't get the diagram to function.

Can anyone out there help me?

Thanks, Bill

Hello Bill -

Can you describe your problem a little more? Are you saying that you have a 2K database that you've attached/restored/transported to 2K5 and you can't create a database diagram on it?

Thanks -

Buck Woody

Database diagram support objects cannot be installed...

I can't make a diagram on our server(Win2003 x64,SQL 2005 Enterprise x64 sp2 3054).

I have tried to login as an admin and create a new db, but get the same message -

'Database diagram support objects cannot be installed because this database does not have a valid owner. To..'

Also tried to make a diagram from the ReportServer db.

Any suggestions?

Two things to check.

1. please make sure that db has a owner (as the error suggests).

2. please check your compatibility level.

|||

Thanks Meher for your reply.

1. Both of the databases I tried has a owner.

2. I'm pretty sure the compatibility level is 90 (SQL 2005) since one is created during installation(ReportServer) and the other is created as a new db in SQL Management Studio. (To be sure I will check next week)

Any other suggestions?

|||

Are you still getting the error message?. As you have mentioned check the compatibility level once again and if you are still getting the message we can look a bit further.

|||

The compatibility level is 90(SQL Server 2005).

|||

what role do you belong to?. pls check

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/uirfsql9/html/6fdecefb-7bd3-4203-a58c-36d46ee628bf.htm

|||db_owner |||

Hi olof,

can you please go through the steps outlined in section 4.8.1 in http://support.microsoft.com/?id=910228

As per the section in the article, looks like you might have to install the diagram support.

To create database diagrams, change the database compatibility level to 2005, install database diagram support, and then return the database to the desired database compatibility level.

MVPs, please correct me if I am missing something.

Thanks

Meher

|||

one other thing I forgot to mention is that the installation of support objects can fail if the database

has been attached or restored from another instance of SQL Server. In such a case there is a

possibility that the database owner name stored in the database may not be a valid logon for the

instance of the SQL Server on to which the database is restored to (or attached to).

I would suggest if thats the case then you can use the Alter statement to change the owner to a valid logon.

ALTER AUTHORIZATION ON DATABASE::your dbname TO yourdesiredlogin

(please see BOL for more details on ALTER AUTHORIZATION).

I would suggest doing through T-SQL than UI and see if it solves your issue.

Thanks

Meher


Saturday, February 25, 2012

Database design question

I have a series of database objects that represent things such as people,
accounts, etc. I have a set of options (boolean) that I need to add to
these objects. Normally I would just create a bit field for each one and be
done with it. The challenge however is that there could be hundreds of
these options (maybe 300) and a user decides which of these options
(actually attributes) that should apply to these db objects.
For example, a user can create a new type of person object. What makes this
person object different is the fact that it has a unique set of these
attributes. So whenever someone creates a new instance of this person
object (another one), it contains these attributes (whose values can be set
uniquely).
These attributes are mainly for searching, in other words, you can flag an
account with some of these attributes and then search on them. In terms of
database design, what is a good approach? I was thinking of having a master
list of all the available attributes in a separate table. Then a separate
table containing the mappings to the types (e.g. persontype1 has attribute
1,3,4,5,6...). Then a third table containing the specific instances of
these persons and their value (e.g. 'bob' of persontype1 values for 1=on,
3=off, etc.).
If this is the case, how would would one search on these items? It seems
that the code to build the searching (considering all the items are dynamic)
would be very ugly.
Sorry if this isn't totally clear, this is actually the first time I am
explaining it on paper (well sort of).>> I have a series of database objects that represent things such as
people, accounts, etc. I have a set of options (boolean) that I need
to add to these objects. Normally I would just create a bit field
[sic] for each one and be
done with it. <<
Series? SQL uses sets. Booleans? SQL has no boolean data type. You
are probably about to detroy your data integrity with a EAV design.
options [sic] (maybe 300) <<
Options? Well, at least you know they are really attributes. An
object does not have optional attributes; it is the sum of all its
attributes in an RDBMS. This is foundations, not rocket science.
should apply to these db objects. <<
I certainly hope not! You are supposed to know what you are doing and
not let any random user design the schema.
You then describe mixing data and metadata in such a way that you will
never have data integrity. Stop what you are doing and read a book
RDBMS basics; you missed the whole concept.|||300 *boolean* attributes! I wonder how many you would really need if
you modelled the same attributes with well-chosen codes and valued
attributes instead of check boxes (which I bet is the origin of this
design). 300 bits of data is actually very little.
Represent classes and sub-classes with the common attributes in a
common table and the specific attributes in related tables sharing the
same primary key. Optional attributes can also be nullable or use
tokens for the inapplicable values.
David Portas
SQL Server MVP
--|||Tim Mavers wrote:
> I have a series of database objects that represent things such as people,
> accounts, etc. I have a set of options (boolean) that I need to add to
> these objects. Normally I would just create a bit field for each one and
be
> done with it. The challenge however is that there could be hundreds of
> these options (maybe 300) and a user decides which of these options
> (actually attributes) that should apply to these db objects.
> For example, a user can create a new type of person object. What makes th
is
> person object different is the fact that it has a unique set of these
> attributes. So whenever someone creates a new instance of this person
> object (another one), it contains these attributes (whose values can be se
t
> uniquely).
> These attributes are mainly for searching, in other words, you can flag an
> account with some of these attributes and then search on them. In terms o
f
> database design, what is a good approach? I was thinking of having a mast
er
> list of all the available attributes in a separate table. Then a separate
> table containing the mappings to the types (e.g. persontype1 has attribute
> 1,3,4,5,6...). Then a third table containing the specific instances of
> these persons and their value (e.g. 'bob' of persontype1 values for 1=on,
> 3=off, etc.).
> If this is the case, how would would one search on these items? It seems
> that the code to build the searching (considering all the items are dynami
c)
> would be very ugly.
> Sorry if this isn't totally clear, this is actually the first time I am
> explaining it on paper (well sort of).
>
I think you've done a good job with design if I understood you correctly.
I presume you have a 3 tables: Person, Attribute and PersonAttribute.
PersonAtribute is N:N link that has PersonID and AttributeID.
One way to preform search is to create a stored procedure which will
find all persons who have a set of attributes linked to it. Pass the
selected attributes to a procedure as a parameter and then join them
with Persons thru PersonAttribute.|||You will either have the 300 characteristics in the person table or slap it
in an "enumeration" table. With the second direction, you put 300 bools in a
"profile" type of table and then link the person to a particular profile
based on the answers to the question. This will make the initial insert
slower, as you will have to check to determine which "type" of person you ar
e
dealing with.
The other option is to determine ways of grouping this information (break
booleans down to groupings), but you will still end up with either embedding
this info in your table or placing it in a "profile" table.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Tim Mavers" wrote:

> I have a series of database objects that represent things such as people,
> accounts, etc. I have a set of options (boolean) that I need to add to
> these objects. Normally I would just create a bit field for each one and
be
> done with it. The challenge however is that there could be hundreds of
> these options (maybe 300) and a user decides which of these options
> (actually attributes) that should apply to these db objects.
> For example, a user can create a new type of person object. What makes th
is
> person object different is the fact that it has a unique set of these
> attributes. So whenever someone creates a new instance of this person
> object (another one), it contains these attributes (whose values can be se
t
> uniquely).
> These attributes are mainly for searching, in other words, you can flag an
> account with some of these attributes and then search on them. In terms o
f
> database design, what is a good approach? I was thinking of having a mast
er
> list of all the available attributes in a separate table. Then a separate
> table containing the mappings to the types (e.g. persontype1 has attribute
> 1,3,4,5,6...). Then a third table containing the specific instances of
> these persons and their value (e.g. 'bob' of persontype1 values for 1=on,
> 3=off, etc.).
> If this is the case, how would would one search on these items? It seems
> that the code to build the searching (considering all the items are dynami
c)
> would be very ugly.
> Sorry if this isn't totally clear, this is actually the first time I am
> explaining it on paper (well sort of).
>
>|||Tim Mavers (webview@.hotmail.com) writes:
> These attributes are mainly for searching, in other words, you can flag
> an account with some of these attributes and then search on them. In
> terms of database design, what is a good approach? I was thinking of
> having a master list of all the available attributes in a separate
> table. Then a separate table containing the mappings to the types (e.g.
> persontype1 has attribute 1,3,4,5,6...). Then a third table containing
> the specific instances of these persons and their value (e.g. 'bob' of
> persontype1 values for 1=on, 3=off, etc.).
Hm, if I understand this correctly, you appear to need more tables.
First there is:
CREATE TABLE attributes (attributeid int NOT NULL,
attributename varchar(50) NOT NULL,
CONSTRAINT pk_attributes PRIMARY KEY (attributeid))
Then you have:
CREATE TABLE persontyoes (persontypeid int NOT NULL,
persontypename varchar(50) NOT NULL,
CONSTRAINT pk_persontypes PRIMARY KEY (persontypeid))
Which defines the possible persontypes. Whether this should really be
an objecttypes table, or you should have one table for persons, another
for accounts etc I can't really tell with the scant information that I
have.
Then to define which attributes that are possible for a person type:
CREATE TABLE persontypeattributes (persontypeid NOT NULL,
attributeid NOT NULL,
CONSTRAINT pk_personstypeattr PRIMARY KEY (persontypeid,
attreibuteid), CONSTRAINT fk1_persontype FORIEGN KEY (persontypeid)
REFERENCES persontypes (persontypeid),
CONSTRAINT fk2_attribute FOREIGN KEY (attributeid)
REFERNCES attributes (attributeid)
Then you would need a column in the persons table to identify the
persontype - or if a person can belong to more than one person table,
you need a personpersontypes table. And finally you would need a
personattributes table. This last table is a little tricky, because
you somehow need to ascertain that the attributes applicable to the
person's person type(s) go into the table. You probably need a trigger
for that.

> If this is the case, how would would one search on these items? It
> seems that the code to build the searching (considering all the items
> are dynamic) would be very ugly.
I'm not really sure how these searches really looks like. But if a user
searches for users with certain settings flags of five attributes (and
the rest thus "don't care"), I think you could do something like:
SELECT personid
FROM personatttributes pa
JOIN searchcriteris sa ON pa.attributeid = sa.attributeid
AND pa.attributeval = sa.attributeval
WHERE sa.searchkey = @.searchkey
GROUP BY personid
HAVING COUNT(*) = (SELECT COUNT(*)
FROM searchcriteria
WHERE searchkey = @.searchkey)
That is, you would shove down the uses choices in a table, and identify
each search with some session key.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks for the all the replies so far. Right now I have:
Person Table (name, phone, etc.)
I have a pre-set list of attributes (attributes for a person). These mostly
consist of yes/no values, but some are can contain numbers or text.
Functionally, special PersonTypes (like MarketingPerson, EducationalPerson,
etc.) need to be created. What makes them a specific type is the set of
these attributes (for lack of a better term) that needs to be assigned to
them. So again funcitonally, someone will go in and define a
"MarketingPerson" and select one or more of these values to be included.
When someone creates a new MarketingPerson, those new attributes (booleans,
text fields,etc) are available even though they really aren't part of the
"Person" table.
I am concerned about searching? Having so many attributes available can
generate a really ugly (and large) query, correct?
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns960E128F8CDAYazorman@.127.0.0.1...
> Tim Mavers (webview@.hotmail.com) writes:
> Hm, if I understand this correctly, you appear to need more tables.
> First there is:
> CREATE TABLE attributes (attributeid int NOT NULL,
> attributename varchar(50) NOT NULL,
> CONSTRAINT pk_attributes PRIMARY KEY (attributeid))
> Then you have:
> CREATE TABLE persontyoes (persontypeid int NOT NULL,
> persontypename varchar(50) NOT NULL,
> CONSTRAINT pk_persontypes PRIMARY KEY (persontypeid))
> Which defines the possible persontypes. Whether this should really be
> an objecttypes table, or you should have one table for persons, another
> for accounts etc I can't really tell with the scant information that I
> have.
> Then to define which attributes that are possible for a person type:
> CREATE TABLE persontypeattributes (persontypeid NOT NULL,
> attributeid NOT NULL,
> CONSTRAINT pk_personstypeattr PRIMARY KEY (persontypeid,
> attreibuteid), CONSTRAINT fk1_persontype FORIEGN KEY (persontypeid)
> REFERENCES persontypes (persontypeid),
> CONSTRAINT fk2_attribute FOREIGN KEY (attributeid)
> REFERNCES attributes (attributeid)
> Then you would need a column in the persons table to identify the
> persontype - or if a person can belong to more than one person table,
> you need a personpersontypes table. And finally you would need a
> personattributes table. This last table is a little tricky, because
> you somehow need to ascertain that the attributes applicable to the
> person's person type(s) go into the table. You probably need a trigger
> for that.
>
> I'm not really sure how these searches really looks like. But if a user
> searches for users with certain settings flags of five attributes (and
> the rest thus "don't care"), I think you could do something like:
> SELECT personid
> FROM personatttributes pa
> JOIN searchcriteris sa ON pa.attributeid = sa.attributeid
> AND pa.attributeval = sa.attributeval
> WHERE sa.searchkey = @.searchkey
> GROUP BY personid
> HAVING COUNT(*) = (SELECT COUNT(*)
> FROM searchcriteria
> WHERE searchkey = @.searchkey)
> That is, you would shove down the uses choices in a table, and identify
> each search with some session key.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp|||Tim Mavers (webview@.hotmail.com) writes:
> I have a pre-set list of attributes (attributes for a person). These
> mostly consist of yes/no values, but some are can contain numbers or
> text.
This can be covered by sql_sqlvariant. The attribute definition would
have a column that defines the data type. This can then be enforced
in a trigger by using sql_variant_property() to find the current data
type.

> I am concerned about searching? Having so many attributes available can
> generate a really ugly (and large) query, correct?
Did you look at this query that I proposed:
Doesn't look ugly to me. However, it may not be effective. In fact, since
I only made it up, it may not even work.
I would be essential to enforce the actual data types for the sql_variants
in searchcriterias too.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Database design question

I have a series of database objects that represent things such as people,
accounts, etc. I have a set of options (boolean) that I need to add to
these objects. Normally I would just create a bit field for each one and be
done with it. The challenge however is that there could be hundreds of
these options (maybe 300) and a user decides which of these options
(actually attributes) that should apply to these db objects.

For example, a user can create a new type of person object. What makes this
person object different is the fact that it has a unique set of these
attributes. So whenever someone creates a new instance of this person
object (another one), it contains these attributes (whose values can be set
uniquely).

These attributes are mainly for searching, in other words, you can flag an
account with some of these attributes and then search on them. In terms of
database design, what is a good approach? I was thinking of having a master
list of all the available attributes in a separate table. Then a separate
table containing the mappings to the types (e.g. persontype1 has attribute
1,3,4,5,6...). Then a third table containing the specific instances of
these persons and their value (e.g. 'bob' of persontype1 values for 1=on,
3=off, etc.).

If this is the case, how would would one search on these items? It seems
that the code to build the searching (considering all the items are dynamic)
would be very ugly.

Sorry if this isn't totally clear, this is actually the first time I am
explaining it on paper (well sort of).>> I have a series of database objects that represent things such as
people, accounts, etc. I have a set of options (boolean) that I need
to add to these objects. Normally I would just create a bit field
[sic] for each one and be
done with it. <<

Series? SQL uses sets. Booleans? SQL has no boolean data type. You
are probably about to detroy your data integrity with a EAV design.

>> The challenge however is that there could be hundreds of these
options [sic] (maybe 300) <<

Options? Well, at least you know they are really attributes. An
object does not have optional attributes; it is the sum of all its
attributes in an RDBMS. This is foundations, not rocket science.

>> and a user decides which of these options (actually attributes) that
should apply to these db objects. <<

I certainly hope not! You are supposed to know what you are doing and
not let any random user design the schema.

You then describe mixing data and metadata in such a way that you will
never have data integrity. Stop what you are doing and read a book
RDBMS basics; you missed the whole concept.|||300 *boolean* attributes! I wonder how many you would really need if
you modelled the same attributes with well-chosen codes and valued
attributes instead of check boxes (which I bet is the origin of this
design). 300 bits of data is actually very little.

Represent classes and sub-classes with the common attributes in a
common table and the specific attributes in related tables sharing the
same primary key. Optional attributes can also be nullable or use
tokens for the inapplicable values.

--
David Portas
SQL Server MVP
--|||Tim Mavers wrote:
> I have a series of database objects that represent things such as people,
> accounts, etc. I have a set of options (boolean) that I need to add to
> these objects. Normally I would just create a bit field for each one and be
> done with it. The challenge however is that there could be hundreds of
> these options (maybe 300) and a user decides which of these options
> (actually attributes) that should apply to these db objects.
> For example, a user can create a new type of person object. What makes this
> person object different is the fact that it has a unique set of these
> attributes. So whenever someone creates a new instance of this person
> object (another one), it contains these attributes (whose values can be set
> uniquely).
> These attributes are mainly for searching, in other words, you can flag an
> account with some of these attributes and then search on them. In terms of
> database design, what is a good approach? I was thinking of having a master
> list of all the available attributes in a separate table. Then a separate
> table containing the mappings to the types (e.g. persontype1 has attribute
> 1,3,4,5,6...). Then a third table containing the specific instances of
> these persons and their value (e.g. 'bob' of persontype1 values for 1=on,
> 3=off, etc.).
> If this is the case, how would would one search on these items? It seems
> that the code to build the searching (considering all the items are dynamic)
> would be very ugly.
> Sorry if this isn't totally clear, this is actually the first time I am
> explaining it on paper (well sort of).

I think you've done a good job with design if I understood you correctly.
I presume you have a 3 tables: Person, Attribute and PersonAttribute.
PersonAtribute is N:N link that has PersonID and AttributeID.

One way to preform search is to create a stored procedure which will
find all persons who have a set of attributes linked to it. Pass the
selected attributes to a procedure as a parameter and then join them
with Persons thru PersonAttribute.|||Tim Mavers (webview@.hotmail.com) writes:
> These attributes are mainly for searching, in other words, you can flag
> an account with some of these attributes and then search on them. In
> terms of database design, what is a good approach? I was thinking of
> having a master list of all the available attributes in a separate
> table. Then a separate table containing the mappings to the types (e.g.
> persontype1 has attribute 1,3,4,5,6...). Then a third table containing
> the specific instances of these persons and their value (e.g. 'bob' of
> persontype1 values for 1=on, 3=off, etc.).

Hm, if I understand this correctly, you appear to need more tables.

First there is:

CREATE TABLE attributes (attributeid int NOT NULL,
attributename varchar(50) NOT NULL,
CONSTRAINT pk_attributes PRIMARY KEY (attributeid))

Then you have:

CREATE TABLE persontyoes (persontypeid int NOT NULL,
persontypename varchar(50) NOT NULL,
CONSTRAINT pk_persontypes PRIMARY KEY (persontypeid))

Which defines the possible persontypes. Whether this should really be
an objecttypes table, or you should have one table for persons, another
for accounts etc I can't really tell with the scant information that I
have.

Then to define which attributes that are possible for a person type:

CREATE TABLE persontypeattributes (persontypeid NOT NULL,
attributeid NOT NULL,
CONSTRAINT pk_personstypeattr PRIMARY KEY (persontypeid,
attreibuteid), CONSTRAINT fk1_persontype FORIEGN KEY (persontypeid)
REFERENCES persontypes (persontypeid),
CONSTRAINT fk2_attribute FOREIGN KEY (attributeid)
REFERNCES attributes (attributeid)

Then you would need a column in the persons table to identify the
persontype - or if a person can belong to more than one person table,
you need a personpersontypes table. And finally you would need a
personattributes table. This last table is a little tricky, because
you somehow need to ascertain that the attributes applicable to the
person's person type(s) go into the table. You probably need a trigger
for that.

> If this is the case, how would would one search on these items? It
> seems that the code to build the searching (considering all the items
> are dynamic) would be very ugly.

I'm not really sure how these searches really looks like. But if a user
searches for users with certain settings flags of five attributes (and
the rest thus "don't care"), I think you could do something like:

SELECT personid
FROM personatttributes pa
JOIN searchcriteris sa ON pa.attributeid = sa.attributeid
AND pa.attributeval = sa.attributeval
WHERE sa.searchkey = @.searchkey
GROUP BY personid
HAVING COUNT(*) = (SELECT COUNT(*)
FROM searchcriteria
WHERE searchkey = @.searchkey)

That is, you would shove down the uses choices in a table, and identify
each search with some session key.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks for the all the replies so far. Right now I have:

Person Table (name, phone, etc.)

I have a pre-set list of attributes (attributes for a person). These mostly
consist of yes/no values, but some are can contain numbers or text.
Functionally, special PersonTypes (like MarketingPerson, EducationalPerson,
etc.) need to be created. What makes them a specific type is the set of
these attributes (for lack of a better term) that needs to be assigned to
them. So again funcitonally, someone will go in and define a
"MarketingPerson" and select one or more of these values to be included.

When someone creates a new MarketingPerson, those new attributes (booleans,
text fields,etc) are available even though they really aren't part of the
"Person" table.

I am concerned about searching? Having so many attributes available can
generate a really ugly (and large) query, correct?

"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns960E128F8CDAYazorman@.127.0.0.1...
> Tim Mavers (webview@.hotmail.com) writes:
>> These attributes are mainly for searching, in other words, you can flag
>> an account with some of these attributes and then search on them. In
>> terms of database design, what is a good approach? I was thinking of
>> having a master list of all the available attributes in a separate
>> table. Then a separate table containing the mappings to the types (e.g.
>> persontype1 has attribute 1,3,4,5,6...). Then a third table containing
>> the specific instances of these persons and their value (e.g. 'bob' of
>> persontype1 values for 1=on, 3=off, etc.).
> Hm, if I understand this correctly, you appear to need more tables.
> First there is:
> CREATE TABLE attributes (attributeid int NOT NULL,
> attributename varchar(50) NOT NULL,
> CONSTRAINT pk_attributes PRIMARY KEY (attributeid))
> Then you have:
> CREATE TABLE persontyoes (persontypeid int NOT NULL,
> persontypename varchar(50) NOT NULL,
> CONSTRAINT pk_persontypes PRIMARY KEY (persontypeid))
> Which defines the possible persontypes. Whether this should really be
> an objecttypes table, or you should have one table for persons, another
> for accounts etc I can't really tell with the scant information that I
> have.
> Then to define which attributes that are possible for a person type:
> CREATE TABLE persontypeattributes (persontypeid NOT NULL,
> attributeid NOT NULL,
> CONSTRAINT pk_personstypeattr PRIMARY KEY (persontypeid,
> attreibuteid), CONSTRAINT fk1_persontype FORIEGN KEY (persontypeid)
> REFERENCES persontypes (persontypeid),
> CONSTRAINT fk2_attribute FOREIGN KEY (attributeid)
> REFERNCES attributes (attributeid)
> Then you would need a column in the persons table to identify the
> persontype - or if a person can belong to more than one person table,
> you need a personpersontypes table. And finally you would need a
> personattributes table. This last table is a little tricky, because
> you somehow need to ascertain that the attributes applicable to the
> person's person type(s) go into the table. You probably need a trigger
> for that.
>> If this is the case, how would would one search on these items? It
>> seems that the code to build the searching (considering all the items
>> are dynamic) would be very ugly.
> I'm not really sure how these searches really looks like. But if a user
> searches for users with certain settings flags of five attributes (and
> the rest thus "don't care"), I think you could do something like:
> SELECT personid
> FROM personatttributes pa
> JOIN searchcriteris sa ON pa.attributeid = sa.attributeid
> AND pa.attributeval = sa.attributeval
> WHERE sa.searchkey = @.searchkey
> GROUP BY personid
> HAVING COUNT(*) = (SELECT COUNT(*)
> FROM searchcriteria
> WHERE searchkey = @.searchkey)
> That is, you would shove down the uses choices in a table, and identify
> each search with some session key.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp|||Tim Mavers (webview@.hotmail.com) writes:
> I have a pre-set list of attributes (attributes for a person). These
> mostly consist of yes/no values, but some are can contain numbers or
> text.

This can be covered by sql_sqlvariant. The attribute definition would
have a column that defines the data type. This can then be enforced
in a trigger by using sql_variant_property() to find the current data
type.

> I am concerned about searching? Having so many attributes available can
> generate a really ugly (and large) query, correct?

Did you look at this query that I proposed:

>> SELECT personid
>> FROM personatttributes pa
>> JOIN searchcriteris sa ON pa.attributeid = sa.attributeid
>> AND pa.attributeval = sa.attributeval
>> WHERE sa.searchkey = @.searchkey
>> GROUP BY personid
>> HAVING COUNT(*) = (SELECT COUNT(*)
>> FROM searchcriteria
>> WHERE searchkey = @.searchkey)
>>
>> That is, you would shove down the uses choices in a table, and identify
>> each search with some session key.

Doesn't look ugly to me. However, it may not be effective. In fact, since
I only made it up, it may not even work.

I would be essential to enforce the actual data types for the sql_variants
in searchcriterias too.

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

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

Database design question

I'm in the process of designing a database and would like some
suggestion on how to architect it.

I have 3 'objects', frequency, task, skill.

For each task there is a frequency however for some tasks there are a
number of different skills, each of which have different frequencies,
so, for example, imagine frequencies being time in minutes. Each task
has to be done a certain number of times but certain tasks have varied
skill levels and each skill level has different frequencies associated
with it.

Task 1, Freq 5min
Task 2, Freq 10min
Task 3, Skill 1, Freq 5min
Task 3, Skill 2, Freq 15min
Task 4, Skill 1, Freq 10min
Task 4, Skill 2, Freq 15min
Task 4, Skill 3, Freq 20min

The problems is that the freq / skill is dependent on the task. I'm
having trouble deciding how to build this database.

I could just hard code the Tasks/Skill in a table so that I have

TaskID PK
Task
Freq

and have records like:

1 Task1 5
2 Task2 10
3 Task3Skill1 5
4 Task3Skill2 15

but I don't like it because it is not easily maintained - in case
freq/skills change.

Does anyone have any ideas. The important information is the
frequency as it will be used to build timetables.>> I have 3 'objects', frequency, task, skill. <<

Basic question - in your business model are these separate entities or
attributes of an entity? What are the dependencies among them? The answer to
these questions lay the foundation for the table design.

>> I could just hard code the Tasks/Skill in a table ... <<

That violates 1NF (assuming tasks & skills are different attributes) and
based on my interpretation of your requirements would cause an update/delete
anomaly. Generally database design cannot be accomplished using Newsgroup
responses since it requires a comprehensive understanding of your underlying
business model, rules & requirements. However, based on a series of
assumptions, here is one way of SQL representation :

CREATE TABLE Tasks (
Task_id INT NOT NULL PRIMARY KEY,
Details VARCHAR(30) NOT NULL,
...);

CREATE TABLE Skills (
Skill_id INT NOT NULL PRIMARY KEY,
Decription VARCHAR(40) NOT NULL,
...);

CREATE TABLE TaskSkills (
Task_id INT NOT NULL
REFERENCES Tasks(Task_id),
Skill_id INT NOT NULL
REFERENCES Skills(Skill_id),
Freq INT NOT NULL
PRIMARY KEY(Task_id, Skill_id));

--
- Anith
( Please reply to newsgroups only )