Showing posts with label regarding. Show all posts
Showing posts with label regarding. Show all posts

Wednesday, March 7, 2012

Multiple Columns Index/Key (does it free me from creating a single column indexes?)

I hope i'm in the right place, but thanks anyway....

Actually i have 2 questions (regarding sql-server Indices/Keys):

1) I have an index, which is consisted of 4 columns.

I've read elsewhere that this index functions (as well) as an index (single column

index) on the first column of this multi-column index.

Does this mean that if i'd like to have (in addition) Indices on all of the 4 columns

seperately i need to define only 3?

2) I have a unique key consisted of multiple columns.

I'd like to save an index to this combination of columns as well (to speed up

things in DB...).

Does the definition of a multiple-columns key free me from defining the multiple-

columns index?

can anyone explain the main diference between Keys and Indices?


thanks,

Ran Kizi

1. Yes, the multi-column index will also function as an index for the first column. In many situations, it will also be an quasi-efficient index for the second, and perhaps other columns. I would get some response measurements before assuming that indexes were required on the lesser columns.

2. A 'unique key' is in fact, a 'Unique CONSTRAINT.

A Primary Key can be created for one or more columns, requires indexing to be efficient, and an index is automatically generated when the Primary Key is created. A Primary Key requires a value, and that the value is unique.

There is no 'Unique Key', but there is a Unique CONSTRAINT. (Perhaps in your question, you were referring to a Primary Key, and if so, the above applies.) A Unique CONSTRAINT can be created for one or more columns, and automatically creates a matching index. A Unique CONSTRAINT does not require a value, but if a value is provided, it must be unique.

A Foreign Key 'should have' an index to be efficient -but the index is NOT automatically generated when the Foreign Key is created. It is recommended that a matching index be created when the Foreign Key is created. A Foreign Key does NOT require a value, BUT if a value is provided, that value must also exist in the table with the Primary Key relationship.

|||

1. Indexes on multiple columns can also be used as index on first column. and in my experience it can not be used as index on second and following columns. you would need to create seprate indexes on those column if your queries will only use second or third column without using first column in queries.

There is a workaround even if you dont have to use first column in your query you can still use COLUMN1 = COLUMN1 only to make optimizer use index as in best of my knowledge if column1 is not present in your query index will be used for second or third column.

2. when you create UNIQUE constraint on multiple columns SQL Server will ultimately create compound unique index on those colunms to make sure uniquenes. for selectivity of index above will apply.

Primary Key does create index automaticaly (if index type is not mentioned and table is heap then will create CLUSTERED INDEX). FORIEGN KEY does not create index automatically and it is highly recomemded to create index on foriegn key column. The one unique reason is when deleting record in primary key table sql server perform a look up in all tables having foriegn key on that table and if no index presented then it will perform clustered index scan or table scan that will ultimately slow down DELETE operation for primary key table.

Multiple Columns Index/Key (does it free me from creating a single column indexes?)

I hope i'm in the right place, but thanks anyway....

Actually i have 2 questions (regarding sql-server Indices/Keys):

1) I have an index, which is consisted of 4 columns.

I've read elsewhere that this index functions (as well) as an index (single column

index) on the first column of this multi-column index.

Does this mean that if i'd like to have (in addition) Indices on all of the 4 columns

seperately i need to define only 3?

2) I have a unique key consisted of multiple columns.

I'd like to save an index to this combination of columns as well (to speed up

things in DB...).

Does the definition of a multiple-columns key free me from defining the multiple-

columns index?

can anyone explain the main diference between Keys and Indices?


thanks,

Ran Kizi

1. Yes, the multi-column index will also function as an index for the first column. In many situations, it will also be an quasi-efficient index for the second, and perhaps other columns. I would get some response measurements before assuming that indexes were required on the lesser columns.

2. A 'unique key' is in fact, a 'Unique CONSTRAINT.

A Primary Key can be created for one or more columns, requires indexing to be efficient, and an index is automatically generated when the Primary Key is created. A Primary Key requires a value, and that the value is unique.

There is no 'Unique Key', but there is a Unique CONSTRAINT. (Perhaps in your question, you were referring to a Primary Key, and if so, the above applies.) A Unique CONSTRAINT can be created for one or more columns, and automatically creates a matching index. A Unique CONSTRAINT does not require a value, but if a value is provided, it must be unique.

A Foreign Key 'should have' an index to be efficient -but the index is NOT automatically generated when the Foreign Key is created. It is recommended that a matching index be created when the Foreign Key is created. A Foreign Key does NOT require a value, BUT if a value is provided, that value must also exist in the table with the Primary Key relationship.

|||

1. Indexes on multiple columns can also be used as index on first column. and in my experience it can not be used as index on second and following columns. you would need to create seprate indexes on those column if your queries will only use second or third column without using first column in queries.

There is a workaround even if you dont have to use first column in your query you can still use COLUMN1 = COLUMN1 only to make optimizer use index as in best of my knowledge if column1 is not present in your query index will be used for second or third column.

2. when you create UNIQUE constraint on multiple columns SQL Server will ultimately create compound unique index on those colunms to make sure uniquenes. for selectivity of index above will apply.

Primary Key does create index automaticaly (if index type is not mentioned and table is heap then will create CLUSTERED INDEX). FORIEGN KEY does not create index automatically and it is highly recomemded to create index on foriegn key column. The one unique reason is when deleting record in primary key table sql server perform a look up in all tables having foriegn key on that table and if no index presented then it will perform clustered index scan or table scan that will ultimately slow down DELETE operation for primary key table.

Multiple Columns Index/Key (does it free me from creating a single column indexes?)

I hope i'm in the right place, but thanks anyway....

Actually i have 2 questions (regarding sql-server Indices/Keys):

1) I have an index, which is consisted of 4 columns.

I've read elsewhere that this index functions (as well) as an index (single column

index) on the first column of this multi-column index.

Does this mean that if i'd like to have (in addition) Indices on all of the 4 columns

seperately i need to define only 3?

2) I have a unique key consisted of multiple columns.

I'd like to save an index to this combination of columns as well (to speed up

things in DB...).

Does the definition of a multiple-columns key free me from defining the multiple-

columns index?

can anyone explain the main diference between Keys and Indices?

1. I'm sure you are in the wrong place, try the SQL Server forums.

2. A Key implies unique data in the column(s) (Unique Key / Primary Key) where as an index doesn't necessarily have to have unique data in the column(s).

3. An index and a key that use the same definitions (same columns etc.) would be redundant, cost space (and possibly performance) and not desired. The optimizer can use either.

4. The first column of an index is always the most important and determines whether the index will be used or not. If you have no better indexes of the first column then it will be used.

BTW - Don't over do it with indexes!

Please ask such question in the SQL Server Forum, this forum is only for Team Edition for Database Professionals.

Alle

Saturday, February 25, 2012

Multiple Collations in SQL Server 2000

Hi all.
Any assistance regarding this would be greatly appreciated.
I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
which is the Greek Character Code. We have a new business requirement where
we need to store Swedish characters as well. Both greek Characters and
Swedishc characters would need to be stored in the same table.
My question is this - could I use the 850 (multilingual) character code to
handle both the Greek and Swedish and also English Characters or would I have
to do something else?
Many thanks.
I suggest you use Unicode datatypes for this. Note that the collation still determines some
nationalization aspects, namely sort order.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
> Hi all.
> Any assistance regarding this would be greatly appreciated.
> I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
> which is the Greek Character Code. We have a new business requirement where
> we need to store Swedish characters as well. Both greek Characters and
> Swedishc characters would need to be stored in the same table.
> My question is this - could I use the 850 (multilingual) character code to
> handle both the Greek and Swedish and also English Characters or would I have
> to do something else?
> Many thanks.
|||Hi Tibor.
Many thanks for that.
Just another question - would the developers need to state the collation
when retrieving the values from the table, or would it be fine to do a std
SELECT statement?
Thanks
"Tibor Karaszi" wrote:

> I suggest you use Unicode datatypes for this. Note that the collation still determines some
> nationalization aspects, namely sort order.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
> news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
>
>
|||> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
It depends... In what way would not the collation for the column(s) in question satisfy the
requirements? If all is OK, then fine. If, you for instance need some different sorting than what
the columns you sort over defines, then yes you would need to add COLLATE tothe ORDER BY clause.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:92EC3872-AA0D-4B71-A5E9-FC8A123714E1@.microsoft.com...[vbcol=seagreen]
> Hi Tibor.
> Many thanks for that.
> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
> Thanks
> "Tibor Karaszi" wrote:

Multiple Collations in SQL Server 2000

Hi all.
Any assistance regarding this would be greatly appreciated.
I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
which is the Greek Character Code. We have a new business requirement where
we need to store Swedish characters as well. Both greek Characters and
Swedishc characters would need to be stored in the same table.
My question is this - could I use the 850 (multilingual) character code to
handle both the Greek and Swedish and also English Characters or would I have
to do something else?
Many thanks.I suggest you use Unicode datatypes for this. Note that the collation still determines some
nationalization aspects, namely sort order.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
> Hi all.
> Any assistance regarding this would be greatly appreciated.
> I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
> which is the Greek Character Code. We have a new business requirement where
> we need to store Swedish characters as well. Both greek Characters and
> Swedishc characters would need to be stored in the same table.
> My question is this - could I use the 850 (multilingual) character code to
> handle both the Greek and Swedish and also English Characters or would I have
> to do something else?
> Many thanks.|||Hi Tibor.
Many thanks for that.
Just another question - would the developers need to state the collation
when retrieving the values from the table, or would it be fine to do a std
SELECT statement?
Thanks
"Tibor Karaszi" wrote:
> I suggest you use Unicode datatypes for this. Note that the collation still determines some
> nationalization aspects, namely sort order.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
> news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
> > Hi all.
> > Any assistance regarding this would be greatly appreciated.
> >
> > I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
> > which is the Greek Character Code. We have a new business requirement where
> > we need to store Swedish characters as well. Both greek Characters and
> > Swedishc characters would need to be stored in the same table.
> > My question is this - could I use the 850 (multilingual) character code to
> > handle both the Greek and Swedish and also English Characters or would I have
> > to do something else?
> >
> > Many thanks.
>
>|||> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
It depends... In what way would not the collation for the column(s) in question satisfy the
requirements? If all is OK, then fine. If, you for instance need some different sorting than what
the columns you sort over defines, then yes you would need to add COLLATE tothe ORDER BY clause.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:92EC3872-AA0D-4B71-A5E9-FC8A123714E1@.microsoft.com...
> Hi Tibor.
> Many thanks for that.
> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
> Thanks
> "Tibor Karaszi" wrote:
>> I suggest you use Unicode datatypes for this. Note that the collation still determines some
>> nationalization aspects, namely sort order.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
>> news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
>> > Hi all.
>> > Any assistance regarding this would be greatly appreciated.
>> >
>> > I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
>> > which is the Greek Character Code. We have a new business requirement where
>> > we need to store Swedish characters as well. Both greek Characters and
>> > Swedishc characters would need to be stored in the same table.
>> > My question is this - could I use the 850 (multilingual) character code to
>> > handle both the Greek and Swedish and also English Characters or would I have
>> > to do something else?
>> >
>> > Many thanks.
>>

Multiple Collations in SQL Server 2000

Hi all.
Any assistance regarding this would be greatly appreciated.
I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
which is the Greek Character Code. We have a new business requirement where
we need to store Swedish characters as well. Both greek Characters and
Swedishc characters would need to be stored in the same table.
My question is this - could I use the 850 (multilingual) character code to
handle both the Greek and Swedish and also English Characters or would I hav
e
to do something else?
Many thanks.I suggest you use Unicode datatypes for this. Note that the collation still
determines some
nationalization aspects, namely sort order.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
> Hi all.
> Any assistance regarding this would be greatly appreciated.
> I currently have my db's set up using the SQL_Latin1_general_CP1253_CI_AI
> which is the Greek Character Code. We have a new business requirement wher
e
> we need to store Swedish characters as well. Both greek Characters and
> Swedishc characters would need to be stored in the same table.
> My question is this - could I use the 850 (multilingual) character code to
> handle both the Greek and Swedish and also English Characters or would I h
ave
> to do something else?
> Many thanks.|||Hi Tibor.
Many thanks for that.
Just another question - would the developers need to state the collation
when retrieving the values from the table, or would it be fine to do a std
SELECT statement?
Thanks
"Tibor Karaszi" wrote:

> I suggest you use Unicode datatypes for this. Note that the collation stil
l determines some
> nationalization aspects, namely sort order.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
> news:9DA9110A-2F37-4878-8702-CB865326FB3F@.microsoft.com...
>
>|||> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
It depends... In what way would not the collation for the column(s) in quest
ion satisfy the
requirements? If all is OK, then fine. If, you for instance need some differ
ent sorting than what
the columns you sort over defines, then yes you would need to add COLLATE to
the ORDER BY clause.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"xyberdobs" <xyberdobs@.discussions.microsoft.com> wrote in message
news:92EC3872-AA0D-4B71-A5E9-FC8A123714E1@.microsoft.com...[vbcol=seagreen]
> Hi Tibor.
> Many thanks for that.
> Just another question - would the developers need to state the collation
> when retrieving the values from the table, or would it be fine to do a std
> SELECT statement?
> Thanks
> "Tibor Karaszi" wrote:
>