Link to home
Start Free TrialLog in
Avatar of SamCash
SamCashFlag for United States of America

asked on

SQL message table optimization

I have a storage requirement relating to messages.  I have 12 fixed length fields,  and one large variable length field.  I believe the large variable length field's length will grow in the near future, when they decide to include graphics. I have this feeling I should use two linked tables, instead of one, as follows.  I m thinking storage size will be reduced and indexing more effective.  What is Best Practices?

Kind Regards
Sam

CREATE TABLE [dbo].[MessageHead](
	[MessageID] [int] NOT NULL,
	[Subject] [nvarchar](128) NOT NULL,
	[CreateDate] [datetimeoffset](7) NOT NULL,
	[CreatedBY] [int] NOT NULL,
	[ModifyDate] [datetimeoffset](7) NULL,
	[ModifiedBY] [int] NULL,
	[ExpireDate] [datetimeoffset](7) NOT NULL,
	[DeleteDate] [datetimeoffset](7) NOT NULL,
	[Publish] [bit] NOT NULL,
	[TextType] [tinyint] NOT NULL,
	[DistributionEID] [int] NOT NULL,
 CONSTRAINT [PK_MessageHead_1] PRIMARY KEY CLUSTERED 
(
	[MessageID] 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

ALTER TABLE [dbo].[MessageHead]  WITH CHECK ADD  CONSTRAINT [FK_MessageHead_Contacts] FOREIGN KEY([CreatedBY])
REFERENCES [dbo].[Contacts] ([ContactID])
GO

ALTER TABLE [dbo].[MessageHead] CHECK CONSTRAINT [FK_MessageHead_Contacts]
GO

ALTER TABLE [dbo].[MessageHead]  WITH CHECK ADD  CONSTRAINT [FK_MessageHead_Contacts1] FOREIGN KEY([ModifiedBY])
REFERENCES [dbo].[Contacts] ([ContactID])
GO

ALTER TABLE [dbo].[MessageHead] CHECK CONSTRAINT [FK_MessageHead_Contacts1]
GO

Open in new window

CREATE TABLE [dbo].[Messages](
	[MessageID] [int] NOT NULL,
	[Message] [nvarchar](4000) NULL,
 CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED 
(
	[MessageID] 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

ALTER TABLE [dbo].[Messages]  WITH CHECK ADD  CONSTRAINT [FK_Messages_MessageHead] FOREIGN KEY([MessageID])
REFERENCES [dbo].[MessageHead] ([MessageID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Messages] CHECK CONSTRAINT [FK_Messages_MessageHead]
GO

Open in new window

Avatar of Mlanda T
Mlanda T
Flag of South Africa image

near future, when they decide to include graphics
Considering this, should you not rather use a FILESTREAM? Or pointers to files stored outside the database rather? Plain text can be stored as plain text files. How many records are you looking at... Potentially?
Avatar of SamCash

ASKER

MlandaT,

Thanks much, I will have to read up on FILESTREAM...

From the users view: These are messages that are posted by various managers at different hierarchical levels and then read by lower levels (filtered) when they login to the website.  Analogous to Facebook posts, only currently plain text.  

They are already talking RTF, and .DOC, so I put in a "TextType" field to use to determine which control to use to render.  So in the future I see them wanting to paste in word doc's. with embedded images.

Potentially?  Currently 200,000 per year, they expect double or triple with this added feature.  If they successfully sell to other organizations then it would be a direct multiplier.  All customers are in the same db.

Thanks Again
Sam
ASKER CERTIFIED SOLUTION
Avatar of Preston Cooper
Preston Cooper
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SamCash

ASKER

Thanks much
Sam