Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attributes table

Status
Not open for further replies.

siliond

Programmer
Aug 7, 2003
13
US
I need a table in wich to store attributes of different types

The table should look like this
[attributes]
cod int
value numeric(19,4) or nvarchar(30)

How to solve the attributes problem?


 
Can you expand your questions? I'm not sure what you are asking.
 
Two possible options:

1) Create a three-column table:

Code:
CREATE TABLE attributes (
  cod int,
  value_num numeric(19, 4),
  value_char nvarchar(30)
)

Then store the attribute value in the appropriate column. I would also probably create a check constraint to make sure that only one value was entered per row.

2) Create two tables:

Code:
CREATE TABLE attrib_num (
  cod int,
  value numeric(19, 4)
)

CREATE TABLE attrib_char (
  cod int,
  value nvarchar(30)
)

The solution you pick will depend on how you are going to use the table within your DB.

--James
 
JamesLean, for answer 2)
if I also have a table

[service_attributes]
cod_service int
type_attribute tinyint
cod_attribute int

and type_attribute: 0 for numeric, 1 for nvarchar

How do I join the tables in one query?

 
Can I ask - why don't you just store all the attributes in a single nvarchar field? It will save you a lot of hassle when trying to construct your queries.

If you need to perform arithmetic on the numeric values you can always convert them to numeric when you need to.

--James
 
if I want all the attributes of one table stored as generic attributes in other table.

Exp:
[clients]
id int
type tinyint


index_type tinyint
index numeric(19, 4)

I want a generic approach for attributes storing.
if type=
0 people I need only one index column
1 firms I need 1 index_type colum and 2 index-s column
2
3
.
.
.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top