Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Wednesday, March 21, 2012

Index Order

In my application for the most part we Usually work with the Most Recent Data. If I am indexing on a AutoNumber Field and I set the Order to Descending would that cause it to find my data faster?

Well, that would naturally depend on all the other factors.

But, changing the order of the sort on the index shouldn't affect the data access, as the index is a B-Tree.

It will run the chain in which ever path is needed. Reversing the order will just send it to the left instead of the right.

What fields you have in your index in regards to meeting the needs of the query are more important.

Index on XML to improve speed doesn't work, any suggestion?

I have a xml field in my member table, it stores data like

<field name="n1">v1</field><field name="n2">v2</field> ....

When I retrieve 10 fields from the xml field like

select exfield.value('(field[@.name="n1"]/.)[1]','nvarchar(max)'),exfield.value('(field[@.name="n2"]/.)[1]','nvarchar(max)')..... from members

when returns 2200 records, it takes 37 seconds,

I tried to add different xml index on the xml field, but none of them help.

What do you think if there is an index can help to arthieve that?

thanks

I highly suggest that you read the excellent whitepaper at http://msdn2.microsoft.com/en-us/library/ms345118.aspx. You need to taylor your indexes and queries to your needs and this paper can help you make those decisions.

Regards,

Galex

INDEX ON VARIABLE table

I create a variable table using this statement in my UDF ,I'm like to put an
index on of its field (Internal_ID),How can I do it?
DECLARE @.TBEnrollmentsForActiveClients TABLE(ENROLLMENT_ID
NUMERIC(9),COURSE_CODE VARCHAR(3),
COURSE_YEAR NUMERIC(5),COURSE_SESSION NUMERIC(5),
INTERNAL_ID NUMERIC(9))
ThanksYou cannot explicitly create indexes on a table variable, rather only those
created by unique or primary key constraints. If internal_id is unique,
create a unique constraint on it:
DECLARE @.TBEnrollmentsForActiveClients TABLE
(
ENROLLMENT_ID NUMERIC(9),
COURSE_CODE VARCHAR(3),
COURSE_YEAR NUMERIC(5),
COURSE_SESSION NUMERIC(5),
INTERNAL_ID NUMERIC(9) UNIQUE
)
If it isn't, make it the first column of a unique constraint, and include
additional columns that would make it unique.
BG, SQL Server MVP
www.SolidQualityLearning.com
"Ray5531" <RayAll@.microsft.com> wrote in message
news:etd1LM0VFHA.2124@.TK2MSFTNGP14.phx.gbl...
> I create a variable table using this statement in my UDF ,I'm like to put
an
> index on of its field (Internal_ID),How can I do it?
> DECLARE @.TBEnrollmentsForActiveClients TABLE(ENROLLMENT_ID
> NUMERIC(9),COURSE_CODE VARCHAR(3),
> COURSE_YEAR NUMERIC(5),COURSE_SESSION NUMERIC(5),
> INTERNAL_ID NUMERIC(9))
> Thanks
>|||Dose it make a join on internal_ID boosted.The reason I was trying to create
index on it is that I'm joing this varaible table with another table on
internal_id ..
Thanks
"Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in message
news:uCNjDU0VFHA.2492@.TK2MSFTNGP10.phx.gbl...
> You cannot explicitly create indexes on a table variable, rather only
> those
> created by unique or primary key constraints. If internal_id is unique,
> create a unique constraint on it:
> DECLARE @.TBEnrollmentsForActiveClients TABLE
> (
> ENROLLMENT_ID NUMERIC(9),
> COURSE_CODE VARCHAR(3),
> COURSE_YEAR NUMERIC(5),
> COURSE_SESSION NUMERIC(5),
> INTERNAL_ID NUMERIC(9) UNIQUE
> )
> If it isn't, make it the first column of a unique constraint, and include
> additional columns that would make it unique.
> --
> BG, SQL Server MVP
> www.SolidQualityLearning.com
>
> "Ray5531" <RayAll@.microsft.com> wrote in message
> news:etd1LM0VFHA.2124@.TK2MSFTNGP14.phx.gbl...
> an
>|||Actually ENROLLMENT_ID is unique so I can 100% garanty that combination of
ENROLLMENT_ID and INTERNAL_ID is also unique,how can I say this in code
below?
Thanks
"Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in message
news:uCNjDU0VFHA.2492@.TK2MSFTNGP10.phx.gbl...
> You cannot explicitly create indexes on a table variable, rather only
> those
> created by unique or primary key constraints. If internal_id is unique,
> create a unique constraint on it:
> DECLARE @.TBEnrollmentsForActiveClients TABLE
> (
> ENROLLMENT_ID NUMERIC(9),
> COURSE_CODE VARCHAR(3),
> COURSE_YEAR NUMERIC(5),
> COURSE_SESSION NUMERIC(5),
> INTERNAL_ID NUMERIC(9) UNIQUE
> )
> If it isn't, make it the first column of a unique constraint, and include
> additional columns that would make it unique.
> --
> BG, SQL Server MVP
> www.SolidQualityLearning.com
>
> "Ray5531" <RayAll@.microsft.com> wrote in message
> news:etd1LM0VFHA.2124@.TK2MSFTNGP14.phx.gbl...
> an
>|||Just make both part of the unique constraint or primary key:
DECLARE @.TBEnrollmentsForActiveClients TABLE
(
ENROLLMENT_ID NUMERIC(9),
COURSE_CODE VARCHAR(3),
COURSE_YEAR NUMERIC(5),
COURSE_SESSION NUMERIC(5),
INTERNAL_ID NUMERIC(9),
UNIQUE(ENROLLMENT_ID, INTERNAL_ID)
)
or
DECLARE @.TBEnrollmentsForActiveClients TABLE
(
ENROLLMENT_ID NUMERIC(9),
COURSE_CODE VARCHAR(3),
COURSE_YEAR NUMERIC(5),
COURSE_SESSION NUMERIC(5),
INTERNAL_ID NUMERIC(9),
PRIMARY KEY(ENROLLMENT_ID, INTERNAL_ID)
)
BG, SQL Server MVP
www.SolidQualityLearning.com
"Ray5531" <RayAll@.microsft.com> wrote in message
news:#BGDjd0VFHA.2700@.TK2MSFTNGP12.phx.gbl...
> Actually ENROLLMENT_ID is unique so I can 100% garanty that combination
of
> ENROLLMENT_ID and INTERNAL_ID is also unique,how can I say this in code
> below?
> Thanks
> "Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in
message
> news:uCNjDU0VFHA.2492@.TK2MSFTNGP10.phx.gbl...
include
put
>|||Sure can.
Just keep in mind that the optimizer doesn't maintain statistics for table
variables like it does for regular and temp tables. So make sure you
benchmark solutions with temp tables as well, comparing the performence with
table variables.
BG, SQL Server MVP
www.SolidQualityLearning.com
"Ray5531" <RayAll@.microsft.com> wrote in message
news:#hu8xY0VFHA.1044@.TK2MSFTNGP10.phx.gbl...
> Dose it make a join on internal_ID boosted.The reason I was trying to
create
> index on it is that I'm joing this varaible table with another table on
> internal_id ..
> Thanks
> "Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in
message
> news:uCNjDU0VFHA.2492@.TK2MSFTNGP10.phx.gbl...
include
put
>|||Thanks
"Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in message
news:uwkDwU1VFHA.2128@.TK2MSFTNGP14.phx.gbl...
> Just make both part of the unique constraint or primary key:
> DECLARE @.TBEnrollmentsForActiveClients TABLE
> (
> ENROLLMENT_ID NUMERIC(9),
> COURSE_CODE VARCHAR(3),
> COURSE_YEAR NUMERIC(5),
> COURSE_SESSION NUMERIC(5),
> INTERNAL_ID NUMERIC(9),
> UNIQUE(ENROLLMENT_ID, INTERNAL_ID)
> )
> or
> DECLARE @.TBEnrollmentsForActiveClients TABLE
> (
> ENROLLMENT_ID NUMERIC(9),
> COURSE_CODE VARCHAR(3),
> COURSE_YEAR NUMERIC(5),
> COURSE_SESSION NUMERIC(5),
> INTERNAL_ID NUMERIC(9),
> PRIMARY KEY(ENROLLMENT_ID, INTERNAL_ID)
> )
> --
> BG, SQL Server MVP
> www.SolidQualityLearning.com
>
> "Ray5531" <RayAll@.microsft.com> wrote in message
> news:#BGDjd0VFHA.2700@.TK2MSFTNGP12.phx.gbl...
> of
> message
> include
> put
>|||I know that sql server hugely uses statistics to execute queries iin the
best way,but I just wondred how it uses statistcs and what are they? why we
should update them with fullscan sometimes?
Thanks
"Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in message
news:eeEcYV1VFHA.2572@.TK2MSFTNGP14.phx.gbl...
> Sure can.
> Just keep in mind that the optimizer doesn't maintain statistics for table
> variables like it does for regular and temp tables. So make sure you
> benchmark solutions with temp tables as well, comparing the performence
> with
> table variables.
> --
> BG, SQL Server MVP
> www.SolidQualityLearning.com
>
> "Ray5531" <RayAll@.microsft.com> wrote in message
> news:#hu8xY0VFHA.1044@.TK2MSFTNGP10.phx.gbl...
> create
> message
> include
> put
>|||J-R, try this whitepaper:
http://support.microsoft.com/defaul...kb;en-us;322096
BG, SQL Server MVP
www.SolidQualityLearning.com
"J-R" <RayAll@.microsft.com> wrote in message
news:OeCMv01VFHA.2960@.TK2MSFTNGP15.phx.gbl...
> I know that sql server hugely uses statistics to execute queries iin the
> best way,but I just wondred how it uses statistcs and what are they? why
we
> should update them with fullscan sometimes?
> Thanks
> "Itzik Ben-Gan" <itzik@.REMOVETHIS.solidqualitylearning.com> wrote in
message
> news:eeEcYV1VFHA.2572@.TK2MSFTNGP14.phx.gbl...
table
unique,
to
>

Index on Portion of a Field

Is it possible to index a portion of a field. I need to search a large table and look for the left 4 characters in two fields.

1) Does a 'normal' index on the entire fields get used in a search like this?
2) Can you build an index on just the left 4?
3) I could use an indexed view, but the table wasn't built with the right settings and I don't want to rebuild and repopulate the table if I don't have to

Thanks for the insight.

PeteNo, you cannot index a portion of a field.

If you did a search like " WHERE field LIKE 'abcd%' and field2 LIKE 'efgh%' " then I believe you will find that SQL Server will use the index (use Query Analyzer to make sure). SQL Server changes these kinds queries into SEARCHABLE ARGUMENTS (SARGS) that can use indexes (note that this is NOT true of things like " LIKE '%abcd%' )|||If this is something that you really need (indexing on only a prtion of a filed), you could create a computed field that just contains the portion you want to index on.

Monday, March 19, 2012

Index on bit fields in SQL Server Management Studio

I noticed that I can put a bit field in an index in a SQL Server 2000 database, while using the SQL Server Management Studio (shipped with SQL Server 2005). In SQL Enterprise Manager this wasn't possible.

Does SQL Server 2000 support indexes on bit fields and doesn't Enterprise Manager support it, or doesn't SQL Server 2000 support indexes on bit fields and is it a 'bug' of the SQL Server Management Studio?

Thanks.
an index on a bit field gives absolutely no benefit due to the way that sql server handles bit fields.|||My experience tells me that this is not true. When the SQL Server only has to access an index instead of the real table, this can increase performance. In the past we've converted Bit fields to TinyInt, so they could be added to an index (while the only values where 0 and 1). This sometimes resulted in queries that executed more than 10 times as fast as without that field in the index.
|||

but thats not a bit field. . . that is a tinyint.

read as to how bit fields are managed. if you have one bit field it might help. . . but if you have more than one in a table it won't.

I contend, a need for an index on a bit field 'smells' of an unnormalized schema (not in all cases, but 99%)

|||Maybe your right about the unnormalized schema, but creating an extra table for each bit field just for the sake of normalizing makes reading the schema a lot more complicated.

I've been searching, but can't find any information on managing bit fields in SQL Server. Have you got a reference for me were I can find more information?

Thanks for your help.
|||

http://msdn2.microsoft.com/en-us/library/ms177603(SQL.90).aspx

see how bit fields are groupd together as bytes. . . bit fields 1 - 8 are in one byte, bit fields 9 - 16 are in another. . . . and so on? It was the same in SQL 2000.

as far as the 'smell', and I don't mean that as disrespectful, often when there is a bit field there is some other piece of data that can be used or should be tracked.

for example, instead of an 'IsSubscribed' bit field, have a nullable field SubscriptionDate, then selecting 'IsSubscribed' = -1 equates to

select p.id from person where not SubscriptionDate is null

In this case SubscriptionDate contains much more information.

And often times you need to track Subscription information and that should be in another table. Then selecting IsSubscribed = -1 transforms to:

select p.id from Person p inner join Subscription s on p.id = s.personId

|||

Well you actually can create indexes on bit fields in SQL Server 2000, but you can't do it through the Design Table Interface. You could either use T-SQL to do it or if you want to do it Visually, then you could also right-click on the table choose All Tasks->Manage Indexes and you can select bit fields here to create the index.

Now Microsoft discloses the storage implementation of bit field data types, but that doesn't mean that they don't store bit field data types differently for Indexes. Maybe if a bit field is Indexed they store it in the B-Trees in their own byte field instead of in the concatenated fashion that they store the data itself. Doubtful, but possible. Your best bet would be to use Query Analyzer with Show Execution Plan enabled and look at the difference between querying with a Indexed Bit field and without it. If it works I would imagine there are situations where it could be helpful. There are definitely appropriate times when you can/should utilize bit fields (e.g Male/Female), etc...

If you had a very large database and a bit field and you wanted to search your data then an index on that field would work. The question is "Does Microsoft do some unpublished Magic" to take advantage of it, as in store the Bit Field Data differently for Indexes as opposed to data, but the best way to test it would be to setup an appropriate scenario and evaluate the Execution Plan and Performance.

Sam

Wednesday, March 7, 2012

Index Exists?

I asked a question earlier about how to tell of a field exists. Now I'm
needing a query to tell if a particular index (index name) exists.I know I can SELECT INDEXPROPERTY.
Is this the recommended approach?
"Les Stockton" wrote:

> I asked a question earlier about how to tell of a field exists. Now I'm
> needing a query to tell if a particular index (index name) exists.
>|||Index names are not unique by themselves; the index name must be unique only
within the scope of the parent table or view.
IF EXISTS(
SELECT *
FROM sysindexes
WHERE
id = OBJECT_ID('dbo.MyTable') AND
name = 'IndexName'
)
PRINT 'exists'
ELSE
PRINT 'does not exist'
Note that indexes may also support primary key and unique constraints. You
might want to keep this in mind, depending on the reason you are checking
for existence.
Hope this helps.
Dan Guzman
SQL Server MVP
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:104B48DE-467E-4235-B3DE-FA72D8893D4F@.microsoft.com...
>I asked a question earlier about how to tell of a field exists. Now I'm
> needing a query to tell if a particular index (index name) exists.
>|||This method can work as can the sysindexes method I suggested. In fact,
INDEXPROPERTY is probably a better method.
Hope this helps.
Dan Guzman
SQL Server MVP
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:DCCEB372-A292-48BA-9432-7B499962B64C@.microsoft.com...
>I know I can SELECT INDEXPROPERTY.
> Is this the recommended approach?
> "Les Stockton" wrote:
>|||I tried the following from inside EnterpriseManager, but it doesn't return
anything.
SELECT INDEXPROPERTY(OBJECT_ID(TEST_MASTER.UserPreferences'),
'PK_UserPreferences', 'IndexID') AS IdxID
Before doing this, I did a right-click in the list of tables in the
database, and selected
"All Tasks" and then "Manage Indexes". I am able to list that the
UserPreferences table has an index called PK_UserPreferences, which
corresponds to the UserID field in the table.
Any ideas why this isn't working?
I go into the
"Dan Guzman" wrote:

> Index names are not unique by themselves; the index name must be unique on
ly
> within the scope of the parent table or view.
> IF EXISTS(
> SELECT *
> FROM sysindexes
> WHERE
> id = OBJECT_ID('dbo.MyTable') AND
> name = 'IndexName'
> )
> PRINT 'exists'
> ELSE
> PRINT 'does not exist'
> Note that indexes may also support primary key and unique constraints. Yo
u
> might want to keep this in mind, depending on the reason you are checking
> for existence.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
> news:104B48DE-467E-4235-B3DE-FA72D8893D4F@.microsoft.com...
>
>|||You're missing a single quote (') after OBJECT_ID(
Also, make sure you are in the context of the database that contains the
UserPreferences table when you run the query. INDEXPROPERTY will return NULL
if the object id cannot be found in the current database. Use USE
<databasename> to set the context to the correct database.
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:72470E25-FF59-439D-BBFF-10CEA09BD301@.microsoft.com...
>I tried the following from inside EnterpriseManager, but it doesn't return
> anything.
> SELECT INDEXPROPERTY(OBJECT_ID(TEST_MASTER.UserPreferences'),
> 'PK_UserPreferences', 'IndexID') AS IdxID
> Before doing this, I did a right-click in the list of tables in the
> database, and selected
> "All Tasks" and then "Manage Indexes". I am able to list that the
> UserPreferences table has an index called PK_UserPreferences, which
> corresponds to the UserID field in the table.
> Any ideas why this isn't working?
> I go into the
> "Dan Guzman" wrote:
>|||Still doesn't work. Test_Master is the name of the database. I name it
there with the table, as well as I am in the context of the database when
running this query.
It still shows nothing returned.
"Gail Erickson [MS]" wrote:

> You're missing a single quote (') after OBJECT_ID(
> Also, make sure you are in the context of the database that contains the
> UserPreferences table when you run the query. INDEXPROPERTY will return NU
LL
> if the object id cannot be found in the current database. Use USE
> <databasename> to set the context to the correct database.
> --
> Gail Erickson [MS]
> SQL Server Documentation Team
> This posting is provided "AS IS" with no warranties, and confers no rights
> "Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
> news:72470E25-FF59-439D-BBFF-10CEA09BD301@.microsoft.com...
>
>|||> Still doesn't work. Test_Master is the name of the database.
If Test_Master is the database name, then the format you're using in the
OBJECT_ID clause ((TEST_MASTER.UserPreferences') is incorrect. What you have
indicates that TEST_MASTER is the object owner, not the database name. The
correct format must either be 'TEST_MASTER.OwnerName.UserPreferences' or
'TEST_MASTER..UserPreferences'. If dbo is the table owner, then use
'TEST_MASTER.dbo.UserPreferences'
--
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:08DEBC04-6886-4876-A681-C02557732ADD@.microsoft.com...
> Still doesn't work. Test_Master is the name of the database. I name it
> there with the table, as well as I am in the context of the database when
> running this query.
> It still shows nothing returned.
> "Gail Erickson [MS]" wrote:
>|||For a bit less fuss with index properties:
http://milambda.blogspot.com/2005/0...-with-kick.html
ML
http://milambda.blogspot.com/|||Hi Les
A two part name indicates the owner of an object, and then the object name.
So TEST_MASTER.UserPreferences would indicate an object called
.UserPreferences owned by a user called TEST_MASTER.
If you have no such user, you will get null.
As Gail said, you must be in the db to use indexproperty, so you can repalce
TEST_MASTER with the object owner, whether it is dbo or some other user.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:08DEBC04-6886-4876-A681-C02557732ADD@.microsoft.com...
> Still doesn't work. Test_Master is the name of the database. I name it
> there with the table, as well as I am in the context of the database when
> running this query.
> It still shows nothing returned.
> "Gail Erickson [MS]" wrote:
>
>

Sunday, February 19, 2012

index and primary key

By defining a numeric field in table as primary key, will the table be indexed on that particular field?yes, a primary key always gets an index, that's how the database system determines if a value exists already or not (for uniqueness)|||am extending my qn a littl bit

suppose the table has the following structure

myTable
(
myPK bigint identity (Primary key)
myUniqNo bigint
myName varchar (50)
)

can i create an index on myUniqNo, if myUniqNo is unique..|||You can create an index on almost any column, whether it is unique or not. You can create a unique constraint or a unique index on a column if there are no duplicate values in the column.

I'd recommend using a constraint instead of an index unless there is some specific, compelling reason for using the index.

-PatP|||yes you can

but then, if myUniqNo is going to be unique, why do you want an IDENTITY column as the primary key?

and by the way, why bigint? are you planning on having over 2 billion rows?|||but then, if myUniqNo is going to be unique, why do you want an IDENTITY column as the primary key?A surrogate key for the existing surrogate key? That way they can allow updates to their existing column?

Ow, ooo, ow! Quit throwing things, that hurts!!!

-PatP|||Yes, but then they can change the "key" without having to cascade all of the updates...|||I'd recommend using a constraint instead of an index unless there is some specific, compelling reason for using the index.Can you tell us why you'd recommend that? Do you know that when you create a unique constraint you implicitly create a unique index?|||Yes I'm sure Pat knows...I think Pat is spouting party line...M$ reccomends that as well...

Never could figure out why...or maybe we did and I forgot...|||About the only thing that a unique constraint has going for it as opposed to a unique index is that you can have a foreign key dependent on a unique constraint. After that, it gets a bit fuzzy. Does anyone know of any articles where the order of checks is done for an insert in SQL Server? For example, are check constraints checked before foreign keys are? Or do some triggers fire before computed columns are generated? That sort of information might give some insight.|||When UNIQUE constraint gets created, a UNIQUE index gets created at the same time with the same name. If you drop the constraint the index gets dropped with it, also implicitly. Trigger never gets to execute if uniqueness is violated either due to constraint or unique index.

Talking about differences, the only one I see is that while constraint is very strict in respect to controlling RI, unique index can be altered in such a way, where in a batch of 100 rows attempted to be inserted there is 1 duplicate row, 99 will be successfully inserted. Nothing can be done to accomplish the same with unique constraint. That's why MS (and Pat) recommend using constraints over indexes.|||Yes I'm sure Pat knows...I think Pat is spouting party line...M$ reccomends that as well...Not hardly... The only time I "spout party line" is when I'm actually at the party.

Creating a constraint creates metadata. Some programs use metadata now, and more will in the future. Metadata is an important stepping stone toward getting real "relational algebra" tools (especially things like OLAP), which will make life lots easier for everyone as they become more readily available.

-PatP|||dont forget the null.
you have to mention the 1 null...|||according to this thread (http://www.dbforums.com/t998479.html) there is a dodgy way around the "only 1 null in a unique index" problem, but i haven't confirmed that it works, i just bookmarked it|||Not hardly... The only time I "spout party line" is when I'm actually at the party.

Creating a constraint creates metadata. Some programs use metadata now, and more will in the future. Metadata is an important stepping stone toward getting real "relational algebra" tools (especially things like OLAP), which will make life lots easier for everyone as they become more readily available.

-PatP

Good Point...so where's the party?|||according to this thread (http://www.dbforums.com/t998479.html) there is a dodgy way around the "only 1 null in a unique index" problem, but i haven't confirmed that it works, i just bookmarked it

according to ruprect, its as simple as setting the column to not null. :D|||"...unique index can be altered in such a way, where in a batch of 100 rows attempted to be inserted there is 1 duplicate row, 99 will be successfully inserted. "

That is one I haven't seen before.

Got code?|||Never mind. Didn't read your post clearly.

Index and constraint on uniqueidentifier field

Hi,
I have made an index on a uniqueidentifier field.
Now I don't want duplicate values.
Should I set the "is unique" property to true or add an contraints on this
field?
Thanks!if you use a default of newid() you are guaranteed uniqueness, or the
chances of getting a duplicate is miniscule.
You can add a unique index to this column,
create unique index test on tablename(uniquecolumnname)
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Arjen" <boah123@.hotmail.com> wrote in message
news:dcq6a6$v4u$1@.news5.zwoll1.ov.home.nl...
> Hi,
> I have made an index on a uniqueidentifier field.
> Now I don't want duplicate values.
> Should I set the "is unique" property to true or add an contraints on this
> field?
> Thanks!
>|||Let's say that I don't generate an id with newid().
I create an unique index and I add one id two times. Do I receive an error
when adding it for the second time?
Thanks!
"Hilary Cotter" <hilary.cotter@.gmail.com> schreef in bericht
news:euqubdBmFHA.3304@.tk2msftngp13.phx.gbl...
> if you use a default of newid() you are guaranteed uniqueness, or the
> chances of getting a duplicate is miniscule.
> You can add a unique index to this column,
> create unique index test on tablename(uniquecolumnname)
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Arjen" <boah123@.hotmail.com> wrote in message
> news:dcq6a6$v4u$1@.news5.zwoll1.ov.home.nl...
>|||You bet!
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Arjen" <boah123@.hotmail.com> wrote in message
news:dcq9h6$tot$1@.news6.zwoll1.ov.home.nl...
> Let's say that I don't generate an id with newid().
> I create an unique index and I add one id two times. Do I receive an error
> when adding it for the second time?
> Thanks!
>
>
> "Hilary Cotter" <hilary.cotter@.gmail.com> schreef in bericht
> news:euqubdBmFHA.3304@.tk2msftngp13.phx.gbl...
>|||If you don't mind letting the server assign new ids sequentially, then
re-define the column as an identity.
"Arjen" <boah123@.hotmail.com> wrote in message
news:dcq6a6$v4u$1@.news5.zwoll1.ov.home.nl...
> Hi,
> I have made an index on a uniqueidentifier field.
> Now I don't want duplicate values.
> Should I set the "is unique" property to true or add an contraints on this
> field?
> Thanks!
>

Index a bit field

Is there any way to index a bit field in a composite index?Yes, that is, if you are using SQL-Server 2000. Older versions do not
support indexing bit columns.
Gert-Jan
Mark DeWaard wrote:
> Is there any way to index a bit field in a composite index?|||I was able to successfully create an index on a bit field using query
analyzer.
What confused me was that bit fields don't show up in Enterprise manager's
drop down field for indexes. Also many websites still say that bit fields
cannot be indexed
Thank you for your response.
"Gert-Jan Strik" <sorry@.toomuchspamalready.nl> wrote in message
news:3F020E10.B19B4B4E@.toomuchspamalready.nl...
> Yes, that is, if you are using SQL-Server 2000. Older versions do not
> support indexing bit columns.
> Gert-Jan
>
> Mark DeWaard wrote:
> >
> > Is there any way to index a bit field in a composite index?