{"id":20774453,"url":"https://github.com/segovoni/sp_alter_column","last_synced_at":"2025-04-30T15:18:13.384Z","repository":{"id":36135604,"uuid":"169069011","full_name":"segovoni/sp_alter_column","owner":"segovoni","description":"The stored procedure sp_alter_column is able to alter a column with dependencies in your SQL database","archived":false,"fork":false,"pushed_at":"2022-09-17T16:27:22.000Z","size":124,"stargazers_count":16,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-16T14:31:37.881Z","etag":null,"topics":["alter-table","sql-server","stored-procedure","utility"],"latest_commit_sha":null,"homepage":"","language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/segovoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-04T11:32:54.000Z","updated_at":"2023-11-26T17:01:29.000Z","dependencies_parsed_at":"2023-01-16T22:47:22.295Z","dependency_job_id":null,"html_url":"https://github.com/segovoni/sp_alter_column","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segovoni%2Fsp_alter_column","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segovoni%2Fsp_alter_column/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segovoni%2Fsp_alter_column/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segovoni%2Fsp_alter_column/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segovoni","download_url":"https://codeload.github.com/segovoni/sp_alter_column/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225037523,"owners_count":17411080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alter-table","sql-server","stored-procedure","utility"],"created_at":"2024-11-17T12:29:36.227Z","updated_at":"2024-11-17T12:29:36.761Z","avatar_url":"https://github.com/segovoni.png","language":"TSQL","funding_links":[],"categories":["SQL Server Web Resources"],"sub_categories":[],"readme":"[![tSQLt installer and unit testing runner](https://github.com/segovoni/sp_alter_column/actions/workflows/unit-test-runner.yml/badge.svg)](https://github.com/segovoni/sp_alter_column/actions/workflows/unit-test-runner.yml)\n\n# sp_alter_column stored procedure for SQL Server!\n\nThe *sp_alter_column* stored procedure is able to alter a column with dependencies in your SQL Server database!\n\nIf you ever had to change the data type or the name of a column, you may have incurred into the [error message 5074](https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors?view=sql-server-2017#errors-5000-to-5999) 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.\n\nThis is the error you probably faced:\n\n```sql\nMsg 5074, Level 16, State 1, Line 1135 - The object 'objectname' is dependent on column 'columnname'.\n\nMsg 4922, Level 16, State 9, Line 1135 - ALTER TABLE ALTER COLUMN Columnname failed because one or more objects access this column.\n```\n\nChanging 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](https://docs.microsoft.com/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql?view=sql-server-2017) 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.\n\nHow did you solve the problem?\n\nSome 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.\n\nI 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](https://github.com/segovoni/sp_alter_column) was born, and it's now available on this GitHub repository!\n\n## Roadmap\n\nThe roadmap of the *sp_alter_column* is always updated as-soon-as the features planned are implemented. Check the roadmap [here](roadmap.md).\n\n# Getting Started\n\nDownload the [sp-alter-column.sql](/source/sp-alter-column.sql), this script creates the *sp_alter_column* stored procedure in your database!\n\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegovoni%2Fsp_alter_column","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegovoni%2Fsp_alter_column","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegovoni%2Fsp_alter_column/lists"}