I'm trying to know that a table without Clustered Index considered as
Heap Table
That is correct.
and then table with out Primary key what it called as ??.
There is no special or common name for a table on which you haven't defined a primary key. Primary key is a constraint that you can put on the data being inserted into the table. It is optional. It is for you to decide whether you need it or not.
If both are not there then it will be called as Heap Table.
Yes. That is correct. Primary key being absent from a table has no relevance in this case. What matters is that whether it has a clustered index or not. Since it doesn't have clustered index so it will certainly be called a Heap Table.
Primary key will give Logical Order and then what clustered Index will
give or they both will do the same operation.
I've never heard this term Logical Order w.r.t. storage of data/rows of tables in SQL Server. There is a term Physical Storage Order though. Primary key has no say in ordering/storage. It only decides uniqueness of records. Primary key is a constraint which enforces unique values for a column for each row being inserted into the table e.g. you can't have two employees having same ID 1
if you've primary key constraint on the ID column of Employee table. It will cause failure of insertion of a record into the table if constraint isn't being met.
Clustered index decides Physical Storage Order of the rows of a table on the disk. It also causes alteration in storage of data corresponding to rows whenever a row gets added/updated in the table. The alteration is done to enforce the physical storage ordering. Let's say you've an Employee table with below columns:
You define a clustered index on ID column. So this is how rows of the table will be stored on disk:
╔════╦══════════════╦═════════╗
║ ID ║ Name ║ Salary ║
╠════╬══════════════╬═════════╣
║ 1 ║ Jeff Atwood ║ 111 ║
║ 2 ║ Geoff Dalgas ║ 222 ║
║ 3 ║ Jarrod Dixon ║ 333 ║
║ 4 ║ Joel Spolsky ║ 444 ║
╚════╩══════════════╩═════════╝
Now you update the record having ID 2
. You change its ID to 5
. Had it been a Heap table (no clustered index) then no reordering of data storage would be required. The row will get updated in-place (Refer screenshot)
╔════╦══════════════╦═════════╗
║ ID ║ Name ║ Salary ║
╠════╬══════════════╬═════════╣
║ 1 ║ Jeff Atwood ║ 111 ║
║ 5 ║ Geoff Dalgas ║ 222 ║ <- No physical movement of the affected row
║ 3 ║ Jarrod Dixon ║ 333 ║
║ 4 ║ Joel Spolsky ║ 444 ║
╚════╩══════════════╩═════════╝
But this story changes in case you've a clustered index defined on ID column. A hole will get created where the row with ID 2
was present. And the entire row with changed ID 5
will moved to the bottom of the table (Refer screenshot below). Such updates cause fragmentation of table storage which can be resolved by index reorganizing or index rebuilding:
╔════╦══════════════╦═════════╗
║ ID ║ Name ║ Salary ║
╠════╬══════════════╬═════════╣
║ 1 ║ Jeff Atwood ║ 111 ║
║<HOLE causing fragmentation> ║
║ 3 ║ Jarrod Dixon ║ 333 ║
║ 4 ║ Joel Spolsky ║ 444 ║
║ 5 ║ Geoff Dalgas ║ 222 ║ <- Physical movement of the affected row
╚════╩══════════════╩═════════╝