Table structure best practices

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
4/28/2009 8:32:36 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Table structure best practices

Hi

When creating a new Module, what is the going forward best practices for the required fields of a new database table?
Fields that will allow the new Module to work on multiple sites and allow it to have different instances within one site?
I looked through the tables and see that all tables are not the same.

Would it be
 [Guid] uniqueidentifier DEFAULT newid() NOT NULL,
 [SiteGuid] uniqueidentifier NOT NULL,
 [ModuleID] int NOT NULL,
 [ModuleGuid] uniqueidentifier NULL,
with GUID being my table PRIMARY KEY

and what are the different uses of ModuleID vs ModuleGuid?

I have one Module with a table working fine now in one site and did not use any fields that give my module maximum flexability. I'm about to make a second module now and want to do this one right.

Thanks

Rick Hubka

4/29/2009 5:06:17 AM
Gravatar
Total Posts 18439

Re: Table structure best practices

Hi Rick,

I think you are on the right track in following the examples from other tables. I would name your tables with a different prefix than we use in mojoPortal code to make it easier to keep them grouped separate from core tables.

By using a Guid for your primary key you are able to leverage other things in the system for your feature like content rating, content versioning, etc. You can store your ratings and history using your guid as the content guid.

SiteGuid allows building a method on your class to delete your content if the site is deleted using a SitePreDeleteEventHandler.

Redundant guids like ModuleGuid vs ModuleId, PageGuid vs PageId and SiteGuid vs SiteId make it possible in the future to import data from one installation into another, the rows may get a different integer id (in some tables) but the presence of the guid makes it possible to re-establish relationshhips if the integer ids change during import. Originally we started with integer ids  and still use them for joins for the main core features like modules, pages, sites because its slightly faster to join on integers. In newer development I'm generally not adding new integer id columns and just using the guids.

Hope it helps,

Joe

4/29/2009 8:39:56 AM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Table structure best practices

Thanks for the help Joe, I really appreciate the explanations.

BTW... In my process of my mp table browsing, I noticed that several tables like mp_blogs and mp_ContentHistory, etc... use data type ntext. Microsoft will be dropping this data type in some future release.
I think the replacement will be nvarchar(max)

More information on that here..


http://msdn.microsoft.com/en-us/library/ms187993.aspx


Thanks again!

Rick hubka

4/29/2009 8:56:27 AM
Gravatar
Total Posts 18439

Re: Table structure best practices

Hi Rick,

I think they will be making a mistake to drop it, they should keep it for backward compatibility or they will break existing apps and make customers angry. I really doubt they will actually drop it I think they just want everyone to start using varchar(max).

However varchar(max) is not supported in SQL 2000 so if we were to change to use varchar(max) we would immediately abandon support for SQL 2000.

I'm not going to change anything for now, if/when I see them actually drop it in a new version of MS SQL then I will make a decision about it.

For your own custom feature development you can use it if you don't care about SQL 2000 support, but really it needs to be NVarChar(max) to support multiple languages.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.