Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Friday, March 30, 2012

Pros/Cons of Multivalue Database Columns

I'm just wondering what any pros and cons of using multivalue columns in a database are.

I'm designing a database which will have a column for FABRIC_TYPES_AVAILABLE for a certain FURNITURE_ITEM. Each FURNITURE_ITEM can have multiple FABRIC_TYPES_AVAILABLE of course. So I was just going to store a 2 or 3 digit number of the FABRIC_TYPES_AVAILABLE in that row. So I would have something like...34,24,453,32,23,45,67,65,43,21,21,45.

Anyway...thanks in advance for any information. Links I could read would be great too...b/c I did do a bit of searching, but didnt find much.::I'm just wondering what any pros and cons of using multivalue columns in a database are.

I suggest you read a book about database design. This is pretty well explained in about every into chapter about noirmalization that I have ever seen so far.

Look for (at amazon or in your local Bookstore):

"SQL for Dummies".|||do a look up table. they're faster to query than text based columns|||thona thx.

but i do know its not good for normalization; dont exactly have time to go read a book. hehe.

anyway...im going to go head and go for it, or i will use a lookup table.

thx fellaz|||http://www.sqlservercentral.com/columnists/dsumlin/lookupstrategy_printversion.asp

thats about the best info i could find about lookup tables. could you tell me a little bit more about them?

are they basically, just another table, with ID and Value columns for a certain datatype?

If thats true, i understand that...but then in the table where the values from the lookup table go...do you still store your ID as 23,32,43,54,3,25? I mean...if not...how else would a person know what rows to get from the reference table?

this is the way i was originally doing it; so im assuming there is a different/more correct way to do it, which i'm asking you about.|||you will normalize the database now, or you will normalize it in the future. If you don't exactly have the time to read a book, and you don't know how to normalize a database, I question your strength as a developer. I read constantly, and I always make room to read about something. Even if it's in the restroom. (yeah, I got tech mags in there. :))|||You will have three tables:
1. Furniture_Item
Furniture_ItemID
Furnite_Item (description, etc)
Blah blah (but no fabric type info on this table)

Your lookup table:
2.Fabric_Type
Fabric_TypeID
Fabric_Type (the description)

A link table because you have a many to many relationship between your Furniture_Items and Fabric_Type.
3.Item_FabricType
Item_FabricTypeID
Furniture_ItemID
Fabric_TypeID

The third table contains all the FabricTypes per Item,: so you have no FabricTypes on your Furniture_Item table.

I also suggest you do a bit of reading about database design; it's for your own good. :)

HTH

Friday, March 23, 2012

Propagating results of Alter Table to its views

When I alter a table to add columns or change their properties, either in
Enterprise Manager or with T-SQL statements in Query Analyzer, the
alterations are not automatically noticed by the views that use the table.
The only thing I have been able to figure out to do is to find each
potentially affected view and then:
1. Open it in design mode
2. Check or uncheck a field in the Altered table
3. Uncheck or check the same field to restore the view to its original field
selection
4. Close the view and Save it.
Two problems:
1. That's tedious and time-consuming
2. It is easy to miss an affected view.
Can someone advise me as to a better way? (I am mostly using SQL Server 2000
)
Thanks,
Doug MacLeanDoug MacLean wrote:
> When I alter a table to add columns or change their properties, either in
> Enterprise Manager or with T-SQL statements in Query Analyzer, the
> alterations are not automatically noticed by the views that use the table.
> The only thing I have been able to figure out to do is to find each
> potentially affected view and then:
> 1. Open it in design mode
> 2. Check or uncheck a field in the Altered table
> 3. Uncheck or check the same field to restore the view to its original fie
ld
> selection
> 4. Close the view and Save it.
> Two problems:
> 1. That's tedious and time-consuming
> 2. It is easy to miss an affected view.
> Can someone advise me as to a better way? (I am mostly using SQL Server 20
00)
> --
> Thanks,
> Doug MacLean
Firstly, do not use SELECT * in views. It's generally a bad idea to use
SELECT * anywhere in production code. It's a particularly bad idea in
views because of the way views handle changes to the columns.
So assuming you have named columns in all your views, use
sp_refreshview to ensure the view is up to date with changes to its
columns. If you want to add a column you'll have to edit the view
definition of course, which is good practice and not difficult if you
have adequate source control and change control procedures. Table
changes should never be executed by Enterprise Manager in a production
environment.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||David,
Thanks. That's very helpful. It eliminates the need for my 4-step process in
Enterprise Manager.
I wonder if there is a tool to list all of the views that depend on a
specified table, because the other challenge is actually finding all of them
when altering a table.
Best Regards,
--
Doug MacLean
"David Portas" wrote:

> Doug MacLean wrote:
> Firstly, do not use SELECT * in views. It's generally a bad idea to use
> SELECT * anywhere in production code. It's a particularly bad idea in
> views because of the way views handle changes to the columns.
> So assuming you have named columns in all your views, use
> sp_refreshview to ensure the view is up to date with changes to its
> columns. If you want to add a column you'll have to edit the view
> definition of course, which is good practice and not difficult if you
> have adequate source control and change control procedures. Table
> changes should never be executed by Enterprise Manager in a production
> environment.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>|||Greetings,
"Doug MacLean" <DougMacLean@.discussions.microsoft.com> wrote in message
news:C701B020-919E-44B3-A61E-1FCF7AC6AA8D@.microsoft.com...
> David,
> Thanks. That's very helpful. It eliminates the need for my 4-step process
> in
> Enterprise Manager.
> I wonder if there is a tool to list all of the views that depend on a
> specified table, because the other challenge is actually finding all of
> them
> when altering a table.
> Best Regards,
> --
> Doug MacLean
Create the views WITH SCHEMABINDING and you won't be able to change the
table without first dropping the view. This is a good reminder to fix the
view ;-)
Regards,
Neale NOON|||You may want to use this.
select * from INFORMATION_SCHEMA.VIEW_TABLE_USAGE
where table_name = '<table_name>'
-Omnibuzz (The SQL GC)
http://omnibuzz-sql.blogspot.com/|||> I wonder if there is a tool to list all of the views that depend on a
> specified table, because the other challenge is actually finding all of
> them
> when altering a table.
You might find it easier to refresh all views since you cannot rely on
dependency information unless the views were created WITH SCHEMABINDING.
The script below will generate a script to refresh all views in the current
database. You can wrap it in a cursor and execute according to your
preference. BTW, even without 'SELECT *', you can run into issues with
changed datatypes in the referenced tables.
SELECT
'EXEC sp_refreshview ''' +
QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME) +
''''
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'VIEW'
AND OBJECTPROPERTY(OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)
), 'IsMSShipped') = 0
Hope this helps.
Dan Guzman
SQL Server MVP
"Doug MacLean" <DougMacLean@.discussions.microsoft.com> wrote in message
news:C701B020-919E-44B3-A61E-1FCF7AC6AA8D@.microsoft.com...
> David,
> Thanks. That's very helpful. It eliminates the need for my 4-step process
> in
> Enterprise Manager.
> I wonder if there is a tool to list all of the views that depend on a
> specified table, because the other challenge is actually finding all of
> them
> when altering a table.
> Best Regards,
> --
> Doug MacLean
>
> "David Portas" wrote:
>|||Thanks, Neale.
That's an interesting idea to know when I change a table that has one or
more dependent views. So it is a good reminder.
But I KNOW there are views. And what I want is a clean way of finding and
refreshing them. Adding a process of dropping (and then re-adding) them seem
s
tedious.
Thanks Best Regards,
--
Doug MacLean
"Neale NOON" wrote:

> Greetings,
> "Doug MacLean" <DougMacLean@.discussions.microsoft.com> wrote in message
> news:C701B020-919E-44B3-A61E-1FCF7AC6AA8D@.microsoft.com...
>
> Create the views WITH SCHEMABINDING and you won't be able to change the
> table without first dropping the view. This is a good reminder to fix the
> view ;-)
> --
> Regards,
> Neale NOON
>
>|||Dan,
Ahhh!. That's a great idea. Thanks for both the idea and the sample code.
And it's practical because I only do such updates on the production system a
t
times when no one is using it.
You're right. I've already seen the problem that -- even without adding
columns -- the view needs to be refreshed.
Thanks much and Best regards,
--
Doug MacLean
"Dan Guzman" wrote:

> You might find it easier to refresh all views since you cannot rely on
> dependency information unless the views were created WITH SCHEMABINDING.
> The script below will generate a script to refresh all views in the curren
t
> database. You can wrap it in a cursor and execute according to your
> preference. BTW, even without 'SELECT *', you can run into issues with
> changed datatypes in the referenced tables.
> SELECT
> 'EXEC sp_refreshview ''' +
> QUOTENAME(TABLE_SCHEMA) +
> N'.' +
> QUOTENAME(TABLE_NAME) +
> ''''
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'VIEW'
> AND OBJECTPROPERTY(OBJECT_ID(
> QUOTENAME(TABLE_SCHEMA) +
> N'.' +
> QUOTENAME(TABLE_NAME)
> ), 'IsMSShipped') = 0
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Doug MacLean" <DougMacLean@.discussions.microsoft.com> wrote in message
> news:C701B020-919E-44B3-A61E-1FCF7AC6AA8D@.microsoft.com...
>
>

Tuesday, March 20, 2012

Progress Bar in Table Cell

I'm creating a report with several columns. One of which is a percentage
value. The business people have asked that that column show a progress bar of
sorts to give a visual indicator of the percentage complete, in addition to
the textual %. I have tried to figure out how to do this in a table cell but
to no avail. It appears that you can't use an Expression to set the sizing of
an image, rectangle, etc. Anyone have an idea on how this might be done?
Thanks!you could try a chart (one of the bar graphs that are horizontal based).Then
maybe format the chart to remove the legend, scale, title etc
"rSmoke" wrote:
> I'm creating a report with several columns. One of which is a percentage
> value. The business people have asked that that column show a progress bar of
> sorts to give a visual indicator of the percentage complete, in addition to
> the textual %. I have tried to figure out how to do this in a table cell but
> to no avail. It appears that you can't use an Expression to set the sizing of
> an image, rectangle, etc. Anyone have an idea on how this might be done?
> Thanks!|||I had tried that, except you can't put a chart in a table cell. However, your
post led me to try a subreport with a chart in it. That works great. I had
tried a subreport before but hadn't thought to try a chart in it. Thanks for
the help.
"NH" wrote:
> you could try a chart (one of the bar graphs that are horizontal based).Then
> maybe format the chart to remove the legend, scale, title etc
> "rSmoke" wrote:
> > I'm creating a report with several columns. One of which is a percentage
> > value. The business people have asked that that column show a progress bar of
> > sorts to give a visual indicator of the percentage complete, in addition to
> > the textual %. I have tried to figure out how to do this in a table cell but
> > to no avail. It appears that you can't use an Expression to set the sizing of
> > an image, rectangle, etc. Anyone have an idea on how this might be done?
> > Thanks!|||Note: you can put a chart inside a table group header or group footer. In
that case, the chart would be based of all data rows of that particular
group instance (which is what you typically want). The subreport approach
works but is usually not as efficient as table groups.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"rSmoke" <rSmoke@.discussions.microsoft.com> wrote in message
news:7CC6307F-077B-45A8-9BBD-18C451815AD4@.microsoft.com...
>I had tried that, except you can't put a chart in a table cell. However,
>your
> post led me to try a subreport with a chart in it. That works great. I had
> tried a subreport before but hadn't thought to try a chart in it. Thanks
> for
> the help.
> "NH" wrote:
>> you could try a chart (one of the bar graphs that are horizontal
>> based).Then
>> maybe format the chart to remove the legend, scale, title etc
>> "rSmoke" wrote:
>> > I'm creating a report with several columns. One of which is a
>> > percentage
>> > value. The business people have asked that that column show a progress
>> > bar of
>> > sorts to give a visual indicator of the percentage complete, in
>> > addition to
>> > the textual %. I have tried to figure out how to do this in a table
>> > cell but
>> > to no avail. It appears that you can't use an Expression to set the
>> > sizing of
>> > an image, rectangle, etc. Anyone have an idea on how this might be
>> > done?
>> > Thanks!