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 ««123»»

Table Designing Expand / Collapse
Author
Message
Posted Thursday, July 3, 2014 1:44 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 2:19 AM
Points: 2,059, Visits: 1,432
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!
Post #1588743
Posted Friday, July 4, 2014 4:04 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:34 AM
Points: 2,609, Visits: 3,903
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
Post #1589264
Posted Friday, July 4, 2014 4:06 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:34 AM
Points: 2,609, Visits: 3,903
Thanks Everyone for the input.
Post #1589267
Posted Tuesday, July 8, 2014 7:23 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:34 AM
Points: 2,609, Visits: 3,903
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
Post #1590352
Posted Tuesday, July 8, 2014 7:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, September 19, 2014 2:34 PM
Points: 12,923, Visits: 12,342
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 Moden's 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)
Post #1590358
Posted Tuesday, July 8, 2014 8:08 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 6:38 AM
Points: 13,755, Visits: 28,147
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1590377
Posted Tuesday, July 8, 2014 8:10 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:34 AM
Points: 2,609, Visits: 3,903
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??
Post #1590379
Posted Tuesday, July 8, 2014 8:17 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, September 19, 2014 2:34 PM
Points: 12,923, Visits: 12,342
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 Moden's 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)
Post #1590386
Posted Tuesday, July 8, 2014 8:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 6:38 AM
Points: 13,755, Visits: 28,147
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1590391
Posted Tuesday, July 8, 2014 8:30 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:34 AM
Points: 2,609, Visits: 3,903
Thanks Grant for the reply.


Yes there exists foreign key between table Muthal and ConsumableType.
Post #1590392
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse