Skip to main content

Posts

Showing posts from July, 2022

Enable SQL Server Change Tracking using T-SQL

Enable SQL Server Change Tracking using T-SQL You can enable the Change Tracking feature for a table to keep track of the rows which are inserted, updated or deleted.   Change tracking is a way for SQL Server automatically keep track of the rows that have been inserted, updated or deleted in a table. You have to enable the Change tracking at the database level and also on each table that you want to track. Suppose you want to enable change tracking for your database named APPDB, you can use following tsql script:  ALTER DATABASE APPDB SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 7 DAYS, AUTO_CLEANUP = ON) GO Following query list out the database which have Change tracking enabled: SELECT DB_NAME(database_id) [DATABASE_NAME],* FROM sys.change_tracking_databases To enable Change tracking for a particular table use the following script, which enable CT for table named EMP ALTER TABLE dbo.EMP ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF) GO Use the below script to...

How to ungroup items on my taskbar in Windows 11

I want to ungroup items on my taskbar in Windows 11.  Feature not available: Ungrouping functionality is not available in Windows 11 yet!. Moving the Taskbar to any part of the screen and resizing it are not supported yet. Microsoft has rewritten the taskbar code in UWP. Some functionalities are not included yet.  You need to wait for an upgrade which will have this functionality, or have to downgrade to Windows 10 to enable it as of now. How to ungroup? However there are some 3rd party apps which help to have this functionality.  Feedback OS is still under development. You can give feedback or upvote existing feedback for the same issue.

SQL Server script Error: Insufficient result space to convert uniqueidentifier value to char.

Error:    G etting below error while trying to copy data from one table to another: Msg 8170, Level 16, State 2, Line 1004  Insufficient result space to convert uniqueidentifier value to char.   Fix: UserID column which would be having Unique identifier data require more space (36 character). Size is specified as 15 here. To fix it just specify 36 as varchar length or specify Uniqueidentifier as data type for UserID  column.

Batch insert script for large table- Optimize Large SQL Server Insert by Using Batches

Batch insert script for large table-  Optimize Large SQL Server Insert  by Using Batches Here the scenario is to perform large insert of millions of records on SQL Server tables  in an optimized way. Issue :  Sometimes you may have to performs large insert, like bringing millions of data from the application table to a datawarehouse tables. Challenge :  If we perform this as a usual single insert , it may end up taking hours\days to complete ,and may lead to locks/blocks and fill-up the logs.    To avoid large log growths and minimize locks on tables,  we can follow a better optimized way of batchwise insert. Implementation:   We can do it in many ways. Here is a sample script which bring data batchwise from application table to its corresponding DW table. Here the insert is limited to 100000 records per batch. Once it insert 100000 rows it take next 100000 records and insert. It also check if data is already exist in destination table. ...
  Differences between Stored Procedures and User Defined Functions (UDF) in SQL Server. Stored procedures are   precompiled objects that can be reused. Stored procedure have many advantages: Precompiled: SQL server compiles the stored procedure once, store the execution plan and reuse it which save time to create execution plan each time the code runs. Reuse of code: Stored procedure can be used by multiple users and programs once created Security: You can restrict usage of stored procedure by defining execute permission to users. User defined functions are set of codes that accept parameters, perform and action and must return a result as a scalar value or as a result set. It cannot modify data. Function encapsulate frequently performed logic, that can be called from a Select or from a where clause. There are Built in functions and User defined functions. Functions has following advantages: Allows modular programming- It can be called number of times from...