0

My employer has the habit of giving customer specific tables a name, starting with the name of the customer. This makes it difficult to call the sp_rename stored procedure for renaming column names, as you can see:

/*Version 1:*/
sp_rename 'Customer.FinishedProduct.ShortDescr', 'ShortDescription', 'COLUMN';
sp_rename 'Customer.LogTrackAndTrace.StorePreceddure', 'StoredProcedure', 'COLUMN';
/*Version 2:*/
sp_rename '[Customer.FinishedProduct].[ShortDescr]', '[ShortDescription]', 'COLUMN';
sp_rename '[Customer.LogTrackAndTrace].[StorePreceddure]', '[StoredProcedure]', 'COLUMN';

Both versions don't work.

Do you know how this can be written? (The name of a table is 'Customer.FinishedProduct'.)

4
  • 1
    What is the error message? Could you edit your question and add the details as text?
    – John K. N.
    Sep 13, 2023 at 13:40
  • 2
    Add the create table DDL to your question for clarity. If Customer is the table schema name rather than part of the table name itself, I would expect the version 1 scripts to work. If Customer. is part of the table name and the table is in your default schema (e.g. dbo, version 2 scripts should work.
    – Dan Guzman
    Sep 13, 2023 at 13:41
  • Just to reinforce what John said, "don't work" is absolutely unhelpful for anyone who might try to help you. In what way did it not work? Imagine that someone came to you with this problem. What additional information would you need them to share? Sep 13, 2023 at 15:21
  • You could also have a dot in a table name which is not ASCII 46. eg select nchar(46), nchar(183), nchar(65106), nchar(65294)
    – Aardvark
    Sep 13, 2023 at 16:01

1 Answer 1

0

If I understand correctly, your table (or schema?) has the dot/period character - . in the name?

The following example shows how you can rename a column when the object names (both schema and object in this case) have that character in them.

CREATE DATABASE Test
GO

USE Test
GO

CREATE SCHEMA [a.b]
GO

CREATE TABLE [a.b].[c.d]
(
    e INT
)

GO

sp_rename '[a.b].[c.d].[e]', 'New', 'COLUMN';

SELECT * FROM [a.b].[c.d]

enter image description here

1
  • The weird thing is that it works if I only launch one command (from the ones with the square brackets), but when I try to launch both it fails.
    – Dominique
    Sep 15, 2023 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.