SQL Installation
- Create a new instance with required name.
- Select only Database Engine Services, and Local DB. Local DB selection is applicable only for first instance.
- ML Services, Polybase blah blah,SQl Server Repilication are optional.
- Give a proper instance name.
Expose the instance to the LAN
- Open SQL Configuration Manager.
- Expand SQL Server Network Configuration
- Select your instance
- Double click on Named Pipes and enable it.
- Double Click TCP/IP
- Enable
- Listen All - No
- IP Addressess Tab
- All IP addresses have enable option. Enable this for all IP’s in this tab.
- For TCP Port, enter what ever port you want but ensure port is not used. If port is being used then service won’t restart.
- by default 1433 is the default port.
- For IPAll as well, set TCP port
- Restart the instance in the SQL Server Services.
Firewall
- Create or update the inbound and outbound rules with this new port.
Index Fragmentation
SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName
,ind.name AS IndexName
,indexstats.index_type_desc AS IndexType
,indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind ON ind.object_id = indexstats.object_id
AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 10
ORDER BY indexstats.avg_fragmentation_in_percent DESC
Rebuild Index
ALTER INDEX ALL ON <table_name> rebuild
Rows Count
SELECT sc.name + '.' + ta.name TableName ,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc ON ta.schema_id = sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name , ta.name
ORDER BY sc.name DESC