I am just check if my table has Cluster Index or not by running this query
Table Design
CREATE TABLE [dbo].[postTB](
[postID] [bigint] IDENTITY(1,1) NOT NULL,
[slug] [nvarchar](300) NULL,
[title] [varchar](150) NOT NULL,
[postContent] [nvarchar](max) NULL,
[createDate] [datetime] NULL,
[publishDate] [datetime] NULL,
[userID] [bigint] NOT NULL,
[categoryID] [bigint] NOT NULL,
[isShow] [bit] NOT NULL,
[isApproved] [bit] NULL,
[websiteID] [int] NULL,
[miniPostContent] [nvarchar](300) NULL,
[modifedDate] [datetime] NULL,
[pageTitle] [nvarchar](300) NULL,
[pageKeyword] [nvarchar](300) NULL,
[pageDescribtion] [nvarchar](300) NULL,
[CombinedTags] [nvarchar](300) NULL,
[blogImage] [nvarchar](50) NULL,
[postBlogType] [nvarchar](50) NULL,
[postTag] [nvarchar](100) NULL,
[firstname] [nvarchar](50) NULL,
[lastname] [nvarchar](50) NULL,
[contactemail] [nvarchar](50) NULL,
[viewcount] [bigint] NULL CONSTRAINT [DF_postTB_viewcount_1] DEFAULT ((1)),
[blogCategoryTypeID] [int] NULL CONSTRAINT [DF_postTB_blogCategoryTypeID] DEFAULT ((0)),
CONSTRAINT [PK_postTB] PRIMARY KEY CLUSTERED
(
[postID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I am executing this
Execute sp_helpindex [postTB]
But the result is
The object 'postTB' does not exist in database 'cwpros' or is invalid for this operation.
Please help how to properly create cluster if not exist then check using above command?
Best Answer
Seems that either you didn't create your table on the database you are currently querying with
sp_helpindex
or the creation statement failed (or somehow it was dropped).I tested the create script and it worked for me, however you should check if the table exists or not (maybe you didn't execute it, or did on another instance or database). Use this to check if the table has been created or not (assuming you are using SSMS):
Result:
You should see a row with your table's info. If you don't, execute the create statement on the database and run the query again. Troubleshoot if it fails.
Then either use the procedure you mentioned:
Or use this query to check all indexes massively:
Result: