July 23, 2018 at 8:09 am
Hi all,
Was wondering if it was possible to drop an invalid column on a table which a developer has somehow created, without dropping /recreating the whole table (as it's in use).
the column is >128 chars, appears on a select as NULL.. we don't need it..
SELECT *
FROM sys.columns c
WHERE c.name LIKE 'alter procedure%'
EXEC sys.sp_rename @objname = N'Metadata.dbo.ReportSummaryDataSets.[ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]',
@newname = 'AA',
@objtype = 'COLUMN'
have tried dropping the column in MS Studio, using the DROP COLUMN command, and sp_rename, but the name won't allow me to put it in [] - as it already contains these characters
the column name is
name
"ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************"
without the quotes on the end...
any ideas please? else we will have to stop all writing to this table and recreate it without this column
on Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
Dec 28 2012 20:23:12
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
thanks all!
Duncan.
July 23, 2018 at 8:20 am
Can you post the results of running 'SCRIPT TABLE AS CREATE' please?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
July 23, 2018 at 8:26 am
if the " (double quotes) are not part of the column name try:
alter table A drop column "ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************";
July 23, 2018 at 8:31 am
duncanburtenshaw - Monday, July 23, 2018 8:09 AMHi all,
Was wondering if it was possible to drop an invalid column on a table which a developer has somehow created, without dropping /recreating the whole table (as it's in use).the column is >128 chars, appears on a select as NULL.. we don't need it..
SELECT *
FROM sys.columns c
WHERE c.name LIKE 'alter procedure%'EXEC sys.sp_rename @objname = N'Metadata.dbo.ReportSummaryDataSets.[ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]',
@newname = 'AA',
@objtype = 'COLUMN'have tried dropping the column in MS Studio, using the DROP COLUMN command, and sp_rename, but the name won't allow me to put it in [] - as it already contains these characters
the column name is
name
"ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************"without the quotes on the end...
any ideas please? else we will have to stop all writing to this table and recreate it without this column
on Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
Dec 28 2012 20:23:12
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)thanks all!
Duncan.
Have you tried using single quote marks ?
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 23, 2018 at 8:33 am
got this error
SQL2.sql: Error (1,1): ALTER TABLE DROP COLUMN failed because column 'ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************' does not exist in table 'ReportSummaryDataSets'.
July 23, 2018 at 8:33 am
Phil Parkin - Monday, July 23, 2018 8:20 AMCan you post the results of running 'SCRIPT TABLE AS CREATE' please?
USE Metadata
GO
CREATE TABLE dbo.ReportSummaryDataSets (
ReportSummaryDataSetsID INT IDENTITY,
TaskID VARCHAR(100) COLLATE Latin1_General_CI_AS NULL,
OrderlineItemID INT NOT NULL,
ReportType VARCHAR(50) COLLATE Latin1_General_CI_AS NULL,
ReportName VARCHAR(100) COLLATE Latin1_General_CI_AS NOT NULL,
DataSet VARCHAR(255) COLLATE Latin1_General_CI_AS NOT NULL,
RecordCount INT NULL,
BufferDistance INT NULL,
AreaSearched FLOAT NULL,
InScotland INT NULL DEFAULT (0),
[ALTER PROCEDURE [dbo]]]].[AreaToEdge]]]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************] INT NULL
) ON [PRIMARY]
GO
July 23, 2018 at 8:36 am
Just double the closing brackets[ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]
July 23, 2018 at 8:36 am
The double quotes method seems to work, while using single quotes does not, which is interesting.
DROP TABLE IF EXISTS #garbage;
CREATE TABLE #garbage
(
id INT
);
ALTER TABLE #garbage
ADD "ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************" INT;
ALTER TABLE #garbage
DROP COLUMN "ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************";
SELECT * FROM #garbage g
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
July 23, 2018 at 8:40 am
Luis Cazares - Monday, July 23, 2018 8:36 AMJust double the single brackets[ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]
thank you very much all, the command below dropped the column successfully.. much obliged!
alter table ReportSummaryDataSets drop column
[ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]
July 23, 2018 at 8:42 am
Phil Parkin - Monday, July 23, 2018 8:36 AMThe double quotes method seems to work, while using single quotes does not, which is interesting.
DROP TABLE IF EXISTS #garbage;
CREATE TABLE #garbage
(
id INT
);ALTER TABLE #garbage
ADD "ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************" INT;ALTER TABLE #garbage
DROP COLUMN "ALTER PROCEDURE [dbo].[AreaToEdge] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************";SELECT * FROM #garbage g
Thank you for the code sample, here's my suggestion which also works
CREATE TABLE #garbage
(
id INT
);
ALTER TABLE #garbage
ADD [ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************] INT;
SELECT * FROM #garbage g
ALTER TABLE #garbage
DROP COLUMN [ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10/*********************************];
SELECT * FROM #garbage g
DROP TABLE #garbage;
July 23, 2018 at 8:44 am
duncanburtenshaw - Monday, July 23, 2018 8:40 AMthank you very much all, the command below dropped the column successfully.. much obliged!alter table ReportSummaryDataSets drop column
[ALTER PROCEDURE [dbo]].[AreaToEdge]] @WKT VARCHAR(MAX), @SEARCH_DISTANCE INT, @MARGIN INT = 10
/*********************************]
You're welcome.
When dealing with weird names, you could always try to wrap them in QUOTENAME() to get the correct way of escaping the characters. Just be careful with the length of the string.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply