Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Database Design Expand / Collapse
Author
Message
Posted Tuesday, March 24, 2009 10:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 25, 2009 12:07 AM
Points: 2, Visits: 3
I have n number of geometric shapes like triangle, square, rectangle, circle, cone, pyramid, cylinder etc.
How can I store object's information in my database like for square, I have to store only one side, but for cylinder, I have to store circle information as well as other information.

Thanks in advance.
Post #682563
Posted Tuesday, March 24, 2009 11:13 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, May 30, 2014 6:27 PM
Points: 2,808, Visits: 7,175
What sort of information about the shapes do you need to store?
Post #682616
Posted Tuesday, March 24, 2009 11:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 25, 2009 12:07 AM
Points: 2, Visits: 3
I want to store information about attributes of object like sides measures, for a rectangle, width and height, for a cylinder, its height, its circle info etc.
Along with this I have to store its color information also(assume that object has only one color).
Post #682625
Posted Tuesday, March 24, 2009 11:31 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, May 30, 2014 6:27 PM
Points: 2,808, Visits: 7,175
Though i usually avoid EAVs this seems like a case where you could have one table to hold all the attributes.

for example
you could have one table with the shape type and shapeId,

This could link to a table that holds all the attributes for that particular shape
with ShapeId, ShapeAttribute, Value , Units

For ShapeAttribute you could hold the values of height, length, colour, radius, depth etc....

in the Value column you could hold the value of each measure, eg Length = 2 , height = 4

and in the Units column you can put the unit of measure for each value, eg. Kgs, mm , cm etc..

This table could be cleaner with a lookup table for ShapeAttribute.

This is just a quick suggestion though without knowing what the business requirements are (if any)
Post #682641
Posted Sunday, March 29, 2009 3:15 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, November 4, 2012 12:23 PM
Points: 1,893, Visits: 3,932
I have n number of geometric shapes like triangle, square, rectangle, circle, cone, pyramid, cylinder etc.


Hi

I hate to say that but maybe the EAV design may be an option for requirements. You may consider if you create more than one description table as we call it in our company. So there could be one to store measures (as steveb already described), one to store natural numbers, one for references - if you need - one for any text information (not indexed) and so on.

I'm just getting rid of this design by redeveloping the whole system. EAV databases have the benefit that they are flexible to hold any information but they have also many issues:
* You may ran into bad performance issues because you have always to join many and many of tables
* Getting analytic information from this database is almost impossible... Sure it is possible, but also the performance is quiet bad. The only way we have to realize this is using NOLOCK hints what causes incorrect data sometimes...
* Another big problem is that you never know if your objects are valid. Due to the fact that your objects are not stored in their own tables you don't know if the stored data for each object are correct. E.g. a square may have a radius attribute or your circle may have an angle. You don't see from outside.
* Next problem, are your objects still correct. Maybe you have some more complex objects and you add a new property to them or just conclude that your pyramid gets a new property for color which it did not have before. The existing data still don't have the property so you have to INSERT the new property with any default value into the description tables for all existing objects or the front end has to handle the possibility (forever) that the required fields are not available.

You see the EAV design is very flexible, but this is the main problem of this structure.

Sorry for my subjectivity but I fought about fife years against this database design... But this is the reason why I know the issues.

If your object types are finite you should always use own tables for objects! The EAV database design is very simple to start with but you should consider the problems.

Greets
Flo



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #685802
Posted Sunday, March 29, 2009 3:31 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 4:12 PM
Points: 758, Visits: 1,031
Flo raises some very good points.

If your list of shapes is finite and known in advance, then model them individually. You will get better performance, and it's easier to verify that the individual shape data is correct (data integrity).

If your list of shapes is unknown and flexibility is a requirement, then modelling "extended attributes" is a reasonable solution. I would also consider adding to that design some sort of encoded "rule" to ensure that the data that makes up that shape is completed correctly so you can ensure that data integrity is maintained.

Also, make sure you do not make the mistake of doing the following:
1. using a SQLVariant to encode attribute values
2. encoding all attribute values as strings

Use the correct data types! Otherwise performance pretty much goes right out the window.

Good luck.
Post #685804
Posted Sunday, March 29, 2009 3:36 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, November 4, 2012 12:23 PM
Points: 1,893, Visits: 3,932
1. using a SQLVariant to encode attribute values




2. encoding all attribute values as strings


... and now the database would not be slow or maybe corrupt. Now it would be dead!



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #685806
Posted Monday, March 30, 2009 9:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 11, 2013 11:35 AM
Points: 1, Visits: 16
Why not use an table to hold the actual object, the table at minimum consists of a TYPE field to identify the type of object, an ID field for an identifier and and a BLOB field to hold the object. The object could be any data type identified by the TYPE field. With this simple table you can hold any type of object and does not need a myriad of columns and only one index, if the database supports it you can also index on the blob field with a UDF to search for specific objects. I have used this method for over 20 years to store graphics, documents, GIS information, state information, scripts, reports amongst many others and still have not seen a better solution.
Post #686229
Posted Monday, March 30, 2009 1:42 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 4:47 PM
Points: 501, Visits: 784
Here is one way. Create a "master" shape table to reference each individual shape and a separate shape table for each shape. This is done in a way so that only valid shapes may be created and the individual tables must refer to the master entry defined of it. It's not really all that difficult.
create table Shape(
ShapeID Int not null Identity( 1, 1 ),
ShapeType Char( 2 ) not null,
Origin PointType,
Diminsiona TinyInt, -- 1, 2 or 3
Other1 ...,
Other2 ...,
Constraint UQ_Shape Primary Key NonClustered(
ShapeID
),
Constraint CK_ShapeType Check )ShapeType in (
'LN', -- Line or curve
'SP', -- Spline
'PG', -- Polygon( triangle, rectangle, any n-sided shape)
'EL', -- Ellipse( any regular curved shape)
'CY', -- Cylinder
'CN', -- Cone
'CU', -- Cube
'BL' -- Amorphous blob
))
);
go
create unique clustered index UQ_Shape
on Shape(
ShapeID, -- That's right, include the identity field
ShapeType
);
go

-- Now a table and view for every type of shape
-- Lines
create table Line(
LineID int not null,
ShapeType Char( 2 ) not null,
Length Double,
...,
Constraint PK_Line Primary Key Clustered(
LineID,
ShapeType
),
Constraint CK_LineType Check (ShapeType = 'LN'), -- Force only lines in this table
Constraint FK_LineShape Foreign Key (LineID, ShapeType) -- Force it must be a defined shape
references Shape( ShapeID, ShapeType )
);
go

create view LineShape as
select s.ShapeID, s.Origin, ..., l.Length,...
from Shape s
join Line l
on s.ShapeID = l.ShapeID
and s.ShapeType = l.ShapeType
go

-- Ellipsi
create table Ellipse(
EllipseID int not null,
ShapeType Char( 2 ) not null,
Locus PointType not null, -- Must have at least one (circle)
Locus2 PointType
...,
Constraint PK_Ellipse Primary Key Clustered(
EllipseID,
ShapeType
),
Constraint CK_LineType Check (ShapeType = 'EL'), -- Force only ellipsi in this table
Constraint FK_LineShape Foreign Key (LineID, ShapeType) -- Force it must be a defined shape
references Shape( ShapeID, ShapeType )
);

create view EllipseType....

The master table provides a "shape" entity so that other tables can maintain a reference to any shape. Notice that if an entry with ID 17 in the master shape table (Shape) is defined as a "line", then there can only be an entry in the Line table with an identifier value of 17. Thus, there cannot be, say, a Square entity with the ID value of 17. There cannot be an entry in any individual shape table without a entry already in the master table and there cannot be more than one entry in a shape table referring to the same master entry. This enforces the 1:1 relationship between the master table and the multiple other tables.

This technique requires a bit of up front design and analysis. But if you make the effort (each view also requires the proper trigger), you will be able to maintain exactly the data you need for each shape -- and you will find it surprisingly robust, scalable and yet easy to maintain.


Tomm Carr
--
Version Normal Form -- http://groups.google.com/group/vrdbms
Post #686452
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse