SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Schema Design - Attributes Arrangement


Schema Design - Attributes Arrangement

Author
Message
kiran 4243
kiran 4243
SSC-Enthusiastic
SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)SSC-Enthusiastic (127 reputation)

Group: General Forum Members
Points: 127 Visits: 135
Dear Experts,

Please refer to the below schema for your kind perusal. I would like to know whether the colour highlighted attributes can be exist in the same table? because certain category items (Raw Material) doesn't have these characteristics.

CREATE TABLE [RD].[StockItem](
[StockItemID] [int] IDENTITY(1,1) NOT NULL,
[StockCode] [varchar](50) NOT NULL,
[Description1] [varchar](255) NOT NULL,
[Description2] [varchar](255) NULL,
[Description3] [varchar](255) NULL,
[UnitMeasureID] [smallint] NOT NULL,
[StockCategoryID] [smallint] NOT NULL,
[StockSubCategoryID] [smallint] NOT NULL,
[StockClassID] [smallint] NOT NULL,
[ActualWeight] [smallmoney] NULL,
[RecipeFormulationID] [smallint] NULL,
[PostCuringTemperature] [smallint] NULL,
[PostCuringTime] [smallint] NULL,

[InternalNotes] [varchar](1000) NULL,
[CastingWeight] [smallmoney] NULL,
[InsertWeight] [smallmoney] NULL,
[EpoxyWeight] [smallmoney] NULL,
[WastageWeight] [smallmoney] NULL,
[RequiredMaterialWeight] [smallmoney] NULL,

[ObsoleteFlag] [bit] NULL,
[ContainmentFlag] [bit] NULL,
[StockStatusID] [tinyint] NOT NULL,
[ModifiedDateTime] [smalldatetime] NULL
CONSTRAINT [PK_StockItem_StockItemID] PRIMARY KEY NONCLUSTERED
(
[StockItemID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_StockItem_StockCode] UNIQUE CLUSTERED
(
[StockItemID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Thank you.
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)SSC Guru (237K reputation)

Group: General Forum Members
Points: 237527 Visits: 33643
Without knowing more about what constitutes a StockItem, it's hard to say. However this:
[Description1] [varchar](255) NOT NULL,
[Description2] [varchar](255) NULL,[Description2] [varchar](255) NULL,
[Description3] [varchar](255) NULL,

Absolutely freaks me out. That's very much an indication of a place where we can do some normalization to arrive at a better database design.
It's possible that you need to have another table (or probably tables) that let's you define the attributes of distinct types of StockItems, but it's hard to say without knowing more about the requirements.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Mike Good
Mike Good
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4146 Visits: 1109
FWIW, I've administered/created many tables like this, never saw any terrible pain point. Some wasted space maybe. But I am trying to do better, and am pretty sure this is non-optimal. I think the "right" solution would involve subclassing. So you'd have a top-level table has only elements common to all stock items, and subclass tables with the specialized attributes. Fact that you raised the question make me suspect you already know this. Lots of good articles on this, and I'm pretty sure some more experts will weigh in here.



Eirikur Eiriksson
Eirikur Eiriksson
SSC Guru
SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)

Group: General Forum Members
Points: 100350 Visits: 20907
Grant Fritchey - Tuesday, January 9, 2018 6:30 AM
Without knowing more about what constitutes a StockItem, it's hard to say. However this:
[Description1] [varchar](255) NOT NULL,
[Description2] [varchar](255) NULL,[Description2] [varchar](255) NULL,
[Description3] [varchar](255) NULL,

Absolutely freaks me out. That's very much an indication of a place where we can do some normalization to arrive at a better database design.
It's possible that you need to have another table (or probably tables) that let's you define the attributes of distinct types of StockItems, but it's hard to say without knowing more about the requirements.

+100
Cool
What is the data used for?

BTW: Suggest you profile the data and if you have a repetition of non-numerical values, then you should start by popping those into a separate table(s).

Subramaniam Chandrasekar
Subramaniam Chandrasekar
SSC Eights!
SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)SSC Eights! (886 reputation)

Group: General Forum Members
Points: 886 Visits: 348
kiran 4243 - Monday, January 8, 2018 9:17 PM
Dear Experts,

Please refer to the below schema for your kind perusal. I would like to know whether the colour highlighted attributes can be exist in the same table? because certain category items (Raw Material) doesn't have these characteristics.

CREATE TABLE [RD].[StockItem](
[StockItemID] [int] IDENTITY(1,1) NOT NULL,
[StockCode] [varchar](50) NOT NULL,
[Description1] [varchar](255) NOT NULL,
[Description2] [varchar](255) NULL,
[Description3] [varchar](255) NULL,
[UnitMeasureID] [smallint] NOT NULL,
[StockCategoryID] [smallint] NOT NULL,
[StockSubCategoryID] [smallint] NOT NULL,
[StockClassID] [smallint] NOT NULL,
[ActualWeight] [smallmoney] NULL,
[RecipeFormulationID] [smallint] NULL,
[PostCuringTemperature] [smallint] NULL,
[PostCuringTime] [smallint] NULL,

[InternalNotes] [varchar](1000) NULL,
[CastingWeight] [smallmoney] NULL,
[InsertWeight] [smallmoney] NULL,
[EpoxyWeight] [smallmoney] NULL,
[WastageWeight] [smallmoney] NULL,
[RequiredMaterialWeight] [smallmoney] NULL,

[ObsoleteFlag] [bit] NULL,
[ContainmentFlag] [bit] NULL,
[StockStatusID] [tinyint] NOT NULL,
[ModifiedDateTime] [smalldatetime] NULL
CONSTRAINT [PK_StockItem_StockItemID] PRIMARY KEY NONCLUSTERED
(
[StockItemID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_StockItem_StockCode] UNIQUE CLUSTERED
(
[StockItemID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Thank you.

Select table name only and Press Alt + F1 & Cross check....

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search