Showing posts with label exists. Show all posts
Showing posts with label exists. Show all posts

Monday, March 26, 2012

Index Question

Can anyone explain me why there are (_wa) indexes in my
databases when "real" indexes exists. Meaning: I have an
automatic index "showing" an index that has already been
created... any explanation?
The '_wa' indexes are statistics. They are essential for the SQL optimizer
to decide on a good, efficient query plan.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"" <anonymous@.discussions.microsoft.com> wrote in message
news:82ae01c431e6$21bd4df0$a301280a@.phx.gbl...
> Can anyone explain me why there are (_wa) indexes in my
> databases when "real" indexes exists. Meaning: I have an
> automatic index "showing" an index that has already been
> created... any explanation?
sql

Index Question

Can anyone explain me why there are (_wa) indexes in my
databases when "real" indexes exists. Meaning: I have an
automatic index "showing" an index that has already been
created... any explanation?The '_wa' indexes are statistics. They are essential for the SQL optimizer
to decide on a good, efficient query plan.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"" <anonymous@.discussions.microsoft.com> wrote in message
news:82ae01c431e6$21bd4df0$a301280a@.phx.gbl...
> Can anyone explain me why there are (_wa) indexes in my
> databases when "real" indexes exists. Meaning: I have an
> automatic index "showing" an index that has already been
> created... any explanation?

Friday, March 23, 2012

Index Question

Can anyone explain me why there are (_wa) indexes in my
databases when "real" indexes exists. Meaning: I have an
automatic index "showing" an index that has already been
created... any explanation?The '_wa' indexes are statistics. They are essential for the SQL optimizer
to decide on a good, efficient query plan.
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
":)" <anonymous@.discussions.microsoft.com> wrote in message
news:82ae01c431e6$21bd4df0$a301280a@.phx.gbl...
> Can anyone explain me why there are (_wa) indexes in my
> databases when "real" indexes exists. Meaning: I have an
> automatic index "showing" an index that has already been
> created... any explanation?sql

Monday, March 12, 2012

index issues

I would like to know what are the index exists on which table in my entire database.And also i want to rebuild some of them.
How can i do these two things.
Thanks.You can use sp_helpindex tablename to find the indexes on a particular table. This will also give you the columns and the order of them in the index. As for rebuilding them, you have three options. Drop and rebuild, dbcc dbreindex, and dbcc indexdefrag. All three have their pluses, minus, and idiosyncracies. Generally I use them in the following way:

dbcc dbreindex: Small tables. This will create a copy of all of the indexes (remember clustered indexes are really the table itself), and do a quick switch to the new copies.

dbcc indexdefrag: Large indexes where the index is alone in a filegroup. Also, if the database is in simple recovery mode. I am not terribly impressed with the efficiency of indexdefrag, but it does not lock up the table. This is highly valuable for systems that can not be brought down for maintenance. On the downside, it will run your transaction log pretty well, if you are not in simple recovery mode.

drop/rebuild. A decent all purpose tool, but you need to have a bit of downtime available to you, as the tables will have select locks on them, while you rebuild the indices. You also need to have the scripts for the indices handy (which is why I encourage the use of sp_helpindex), in case anything goes wrong. Remember also, the clustered index should be the last to be dropped, and the first to be rebuilt. Also, note. This does not work on Primary Key indices that have a foreign key referencing them.

Hope this helps.|||Thank u very much.

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:
>
>