Changing the Column Name Through StoredProcedure Dynamically

Changing the Column Name Through StoredProcedure Dynamically

Here’s the syntax for the stored procedure:

CREATE PROCEDURE [dbo].[RenameColumn] @tblname as varchar(50), @oldcolnameas varchar(50), @newcolname as varchar(50)ASdeclare  @tblColname varchar(100)set @tblColname =  @tblname +'.' + @oldcolnameBEGIN TRANSACTIONSET QUOTED_IDENTIFIER ONSET TRANSACTION ISOLATION LEVEL SERIALIZABLESET ARITHABORT ONSET NUMERIC_ROUNDABORT OFFSET CONCAT_NULL_YIELDS_NULL ONSET ANSI_NULLS ONSET ANSI_PADDING ONSET ANSI_WARNINGS ONCOMMITBEGIN TRANSACTIONEXECUTE sp_rename   @tblColname   , @newcolname,'COLUMN'COMMITGO

Then, execute this:

exec RenameColumn 'SFDIDs','CompanyID','CID'Here SFDIDS is the table nameCompanyID is the Old column NameCID is the new column Name
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved