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


Table Designing


Table Designing

Author
Message
Lempster
Lempster
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3231 Visits: 1657
Sean Lange (7/2/2014)

And unless this is a distributed system I just don't care for guids. They are exceptionally wide and a complete pita to work with. Debugging and such is very painful to deal with.

You are so right there, Sean. I've worked with a database that consisted almost entirely of GUIDS with little or no enforcement of foreign keys. It wasn't a distributed system, but it was a nightmare!
VastSQL
VastSQL
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4481 Visits: 5157
Bill Talada (7/2/2014)
Set your own standards and stick to them.


Thanks a lot Bill for that crisp and clear steps to be taken care. Thanks Again
VastSQL
VastSQL
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4481 Visits: 5157
Thanks Everyone for the input.
VastSQL
VastSQL
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4481 Visits: 5157
Hi Experts,

Below are the original design and modifications recommended by us. Do i need to add anything or did i miss anything?

--Original Table design
CREATE TABLE ASC
(
[ASCID] UNIQUEIDENTIFIER NOT NULL ,
[MuthalID] UNIQUEIDENTIFIER NOT NULL ,
[ConsumableTypeID] UNIQUEIDENTIFIER NOT NULL ,
[RemainingYield] INT ,
[ReOrderDate] DATETIME ,
[Recommendation] NVARCHAR (50) ,
[CreatedDate] DATETIME NOT NULL ,
[CreatedBy] UNIQUEIDENTIFIER NULL ,
[ModifiedDate] DATETIME NOT NULL ,
[ModifiedBy] UNIQUEIDENTIFIER NULL

)

--Recommendataion from our side.
1) Create a Clustered Index on ASCID.
2) Non Clustered Index on MuthalID.
3) Non Clustered Index on MuthalId,ConsumableTypeId
4) Change ASCID data type to INT (with Identity) to reduce the size of clustered index

TIA
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26412 Visits: 17557
Ratheesh.K.Nair (7/8/2014)
Hi Experts,

Below are the original design and modifications recommended by us. Do i need to add anything or did i miss anything?

--Original Table design
CREATE TABLE ASC
(
[ASCID] UNIQUEIDENTIFIER NOT NULL ,
[MuthalID] UNIQUEIDENTIFIER NOT NULL ,
[ConsumableTypeID] UNIQUEIDENTIFIER NOT NULL ,
[RemainingYield] INT ,
[ReOrderDate] DATETIME ,
[Recommendation] NVARCHAR (50) ,
[CreatedDate] DATETIME NOT NULL ,
[CreatedBy] UNIQUEIDENTIFIER NULL ,
[ModifiedDate] DATETIME NOT NULL ,
[ModifiedBy] UNIQUEIDENTIFIER NULL

)

--Recommendataion from our side.
1) Create a Clustered Index on ASCID.
2) Non Clustered Index on MuthalID.
3) Non Clustered Index on MuthalId,ConsumableTypeId
4) Change ASCID data type to INT (with Identity) to reduce the size of clustered index

TIA


Since these are recommendations I assume this must be something that is not yet built? #1 is a horrible recommendation UNLESS they also implement #4. A clustered index on a guid is just plain awful. Since this is the design phase I would HIGHLY recommend you change the name of the table. ASC is a reserved word and you will constantly be fighting with it. Also, a table name should give you an idea of what it contains. This seems like an abbreviation, I would recommend using an actual name instead.

What about MuthalID and ConsumableTypeID. Both of these are also guids. From this structure I would assume those are foreign keys to another table. Do those tables also have these guids as clustered primary keys? How about CreatedBy? This also seems like another guid as a primary key. Can users be deleted from the system? Are they actual deletes or just soft deletes? Do you have the ability to permanently delete after a soft delete? If you use a guid here you either have to make it a foreign key (which will prevent permanent deletes) or use no foreign key and then you have no clue who performed the action once that user is deleted. All you would be left with is a meaningless guid.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40845 Visits: 32666
I agree with everything Sean said. I'll add to it by questioning the nonclustered indexes that you want to add. Why are you adding those. Do you know you need them or are you just adding an index on foreign key constraints? I wouldn't suggest adding nonclustered indexes without understanding how the queries are being built and whether or not you'll need an index. The constraints themselves won't act as indexes, but if SQL Server knows it can only ever get one row in a join due to an enforced constraint, it's much more likely to do intelligent things in the plan. You may still need indexes on those columns, but, again, I wouldn't put them in there until you prove that you need them and then you may need to make them a covering indexes, depending on the queries needed. So, no, I don't agree with recommendations 2 & 3 without a lot more information.

Also, I don't see a natural constraint? Based on all the other columns in the table, is it OK if they're all exactly the same, numerous times? If so, your keys and constraints are fine (although your data is going to be messy). If not, you should either consider going with a natural key, or, you need to add a constraint to enforce the natural key.

Finally, as for picking a clustered index, what is the most common access path to the data in this table? Frequently, that's the primary key. But not always. I'd define that immediately. You only get one clustered index, so it's the most important part of setting up a table.

----------------------------------------------------
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
VastSQL
VastSQL
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4481 Visits: 5157
Thanks Sean,

The table name is put just for name sake and will be changed.

CreatedBy
ModifiedBy are referring to other tables where they are PKEY and data type GUID.

Do i need to make any other changes??
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26412 Visits: 17557
Ratheesh.K.Nair (7/8/2014)
Thanks Sean,

The table name is put just for name sake and will be changed.


No problem there.


CreatedBy
ModifiedBy are referring to other tables where they are PKEY and data type GUID.


This is exactly what I was saying. These seem to be a FK to other tables with similar guids as a clustered key issue. Also, please consider my comments about why this might be an issue.

If you allow a user to be deleted (and you have established a FK relationship to this table) SQL will not allow the delete of the user row. This could be a big problem. Then consider what happens when you don't establish a foreign key. You are left with a totally useless guid in a column that would tell you who created/modified the row, except that you can't tell anymore because the user was deleted. For me these types of auditing columns are an acceptable place to denormalize your data. I would recommend putting in the user name instead of a foreign key.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40845 Visits: 32666
While I'm not a fan of GUIDs as clustered keys, I've seen it in a production system and it wasn't the end of the world. We did have to deal with some excessive fragmentation issues and the obvious problems of fewer rows stored per page were there. Performance was reduced. It's absolutely not a choice I would make, but if you're already neck deep into that style of design, I wouldn't recommend a complete rewrite and redesign, but you should sure as heck go into it with your eyes really wide open so you're not surprised by some of the issues that are bound to come up.

----------------------------------------------------
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
VastSQL
VastSQL
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4481 Visits: 5157
Thanks Grant for the reply.


Yes there exists foreign key between table Muthal and ConsumableType.
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