. what is the difference between table and index compression (I have googled but it returns we have both table and index )do we need to have both or just index compression
Nothing much, you should only keep in mind that no matter what compression it is, ultimately it would be either pages or rows of index or table that would be compressed. Since clustered index is table itself and when compressed you can say both table or index is compressed. For non clustered index the pages of index will be compressed when compression applied.
If table does not have index and still you want to compress it, then it would be purely table compression with no index. Quoting from Official MS doc
You can configure row and page compression on the following database objects:
A whole table that is stored as a heap.
A whole table that is stored as a clustered index.
A whole nonclustered index.
A whole indexed view.
For partitioned tables and indexes, you can configure the compression option for each partition, and the various partitions of an object do not have to have the same compression setting.
Read MS docs they have lot of valuable information.
I have heap tables which im compressing with adding a Clustered index with the following script .--Index
You simply have to create a clustered index with data compression or page compression
CREATE CLUSTERED INDEX CI_INDEX_1
ON Heap_Talle (C2)
WITH (DATA_COMPRESSION = ROW);
GO
Most of the tables are fragmented nearly 100% and once rebuilding indexes is done will it eliminate fragmentation or do we need to run defrag when does this have to be run . how do we eliminate fragmentation if im doing the incorrect way.
You are doing correct way. If fragmentation > 30 % rebuild and if between 10-30 reorganize. Also for small indexes have page_count < 2000 do not do anything.
Regarding using LIMITED, DETAILED or SAMPLED scan I would suggest you to read Paul Randal's Blog inside-sys-dm_db_index_physical_stats