Wednesday, May 15, 2019

File is too big to be opened by Notepad++

When I tried to open 2.5 GB size text file in Notepad or Notepad ++, I encountered the exception “File is too big to be opened by Notepad++” 

File is too big to be opened by Notepad++
  
Now, how will we open and read this big size file. This blog will explain two approach to read the big size file by using Window PowerShell.

1.     You can simply view the all file content by using get-content command

PS C:\temp> get-content -path Sample.txt

get-content

  
You can apply filter on number of records partial view by using –totalCount option and you can view only first 1000 records.

PS C:\temp> get-content -path Sample.txt -totalcount 1000

totalCount


2.     You can import some segment of file content into another file by using set-content command and then you will be able to open this file.

PS C:\temp> get-content -path Sample.txt -totalcount 1000 | set-content path NewSample.txt


In above command, it imports first 1000 records into file “NewSample.txt”

And also you can skip records while creating new file

PS C:\temp> get-content -path Sample.txt -totalcount 1000 | Select-object -skip 100 | set-content path NewSample.txt

skip


In above command, first it skip 100 records and then rest 900 records will be imported into file “NewSample.txt”

Tuesday, May 14, 2019

SQL - How to truncate system version temporal table


This blog explains how to truncate the system version enabled table (i.e. temporal table) and how to Stop System-Versioning on a System-Versioned Temporal Table

Msg 13545, Level 16, State 1, Line 21
Truncate failed on table 'dbo.Project' because it is not a supported operation on system-versioned tables.

When you will truncate or perform any specific DML operations pn the temporal table eg. dbo. Project, you will get above error message

truncate table dbo.Project


Before performing any DML operation on temporal table, first you need to disable system–versioned table.

To disable system–versioned table, you simply use SYSTEM_VERSIONING = OFF option and after that history table will stop capturing the updates.

To truncate the the system version enabled table, you need to follow below steps

-- Disable the system version table

ALTER TABLE dbo.Project SET (SYSTEM_VERSIONING = OFF);

--Truncate data

Truncate Table dbo.Project

-- Enable the system version table

ALTER TABLE dbo.Project SET ( SYSTEM_VERSIONING = ON );   

Simply you off system-versioning (SYSTEM_VERSIONING = OFF) and you can remove unnecessary data from temporal history table or temporal table without doing versioning of data

Other blogs related to Temporal Table:



SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...