Clustered Index. SQL

Clustered Index plays a crucial role in how SQL does query optimization.

Note, that creating a primary key automatically makes it a clustered index:

E.g.

[1]

CREATE TABLE [dbo].[T1] (
[id] INT IDENTITY (1, 1) NOT NULL PRIMARY KEY,
[customerid] NVARCHAR (MAX) NULL,
[timeinserted] NVARCHAR (MAX) NULL,
[feature] NVARCHAR (MAX) NULL,
[requestcount] INT NULL
);

Execute sp_helpindex [T1]

Output: 

index_name index_description index_keys
PK__T1__3213E83F0D7CDAD3 clustered, unique, primary key id

Note the use of the IDENTITY keyword.  It starts at 1, and keeps incrementing by 1

[2]

If we don’t have a index se up, the stored procedure will tell us accordingly.

CREATE TABLE [dbo].[T2] (
[id] INT IDENTITY (1, 1) NOT NULL,
[customerid] NVARCHAR (MAX) NULL,
[timeinserted] NVARCHAR (MAX) NULL,
[feature] NVARCHAR (MAX) NULL,
[requestcount] INT NULL
);

Execute sp_helpindex [T2]

The object ‘T2’ does not have any indexes, or you do not have permissions.

[3]

So we add the PK constraint to make it a clustered index:

ALTER TABLE [dbo].[T2] ADD CONSTRAINT  PK_Table_id_3    PRIMARY KEY (id)

OR

ALTER TABLE [dbo].[T2] ADD CONSTRAINT  PK_Table_id_3    PRIMARY KEY CLUSTERED (id)

Execute sp_helpindex [T2]

index_name index_description index_keys
PK_Table_id_3 clustered, unique, primary key id

 

References:

 

 

 

 

 

Fiddler Tips

Fiddler is a very useful tool. Some tips

1. Inspectors and Filters Tabs

The most useful tabs for me are ‘Inspectors’ and ‘Filters’.  Note you can use localhost as a filter when trying to debug applications on the local machine.

Check this out.

 

Fiddler.JPG

 

2. Composer

The composer makes it pretty easy to compose requests

3. Fiddler with CURL

When we use curl at the command line to access websites, the traffic doesn’t show up in Fiddler. This is because curl doesn’t use the system proxy by default.  Try this:

curl -x 127.0.0.1:8888 http://www.get.this/

This tells CURL to use Fiddler (on localhost port 8888) as a proxy.

4. HTTPS Traffic

Then there was this other issue where Fiddler would not capture HTTPS traffic.

  • Initially I tried several options, including revert certificate etc none of which worked.
  • I finally decided to so some certificate troubleshooting.
    • http://fiddler.wikidot.com/certfix
    • After installing that Certificate Generator Plugin, things suddenly started working!
    • The one thing I did note is that the ‘Certificate generated by’ had changed.
  • Not quite sure why the issue got resolved. But for now I was able to get past the problem. Phew!

 

capture

 

References: