Coder Social home page Coder Social logo

segovoni / sp_alter_column Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 12.0 124 KB

The stored procedure sp_alter_column is able to alter a column with dependencies in your SQL database

License: MIT License

TSQL 100.00%
sql-server alter-table stored-procedure utility

sp_alter_column's Introduction

tSQLt installer and unit testing runner

sp_alter_column stored procedure for SQL Server!

The sp_alter_column stored procedure is able to alter a column with dependencies in your SQL Server database!

If you ever had to change the data type or the name of a column, you may have incurred into the error message 5074 which indicates that it is impossible to modify the column due to the presence of linked objects such as a Primary Key, Foreign Key, Indexes, Constraints, Statistics and so on.

This is the error you probably faced:

Msg 5074, Level 16, State 1, Line 1135 - The object 'objectname' is dependent on column 'columnname'.

Msg 4922, Level 16, State 9, Line 1135 - ALTER TABLE ALTER COLUMN Columnname failed because one or more objects access this column.

Changing the column name is not a trivial operation especially if the column is referenced in Views, Stored Procedures etc. To execute the rename of a column, there is the sp_rename system Stored Procedure, but for changing the data type of the column, if you don't want to use any third-party tools, you have no other option than to manually create a T-SQL script.

How did you solve the problem?

Some of you have probably deleted manually the linked objects, changed the data type, the size or the properties of the column, and then you may have recreated the previously deleted objects manually. You must have been very careful to avoid chenging the properties of the objects themselves during DROP and CREATE operations.

I have faced several times this issue, so I have decided to create a stored procedure that is able to compose automatically the appropriate DROP and CREATE commands for each object connected to the column I want to modify. This is how the stored procedure sp_alter_column was born, and it's now available on this GitHub repository!

Roadmap

The roadmap of the sp_alter_column is always updated as-soon-as the features planned are implemented. Check the roadmap here.

Getting Started

Download the sp-alter-column.sql, this script creates the sp_alter_column stored procedure in your database!

Enjoy!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.