Questions tagged [sp-rename]

17 questions
18
votes
3 answers

Renaming a column: Incorrect syntax near 'SP_RENAME'.?

ALTER TABLE [TEMP] SP_RENAME '[TEMP].[Day]', 'GT', 'COLUMN' I am trying to rename Day to GT and am getting the error Incorrect syntax near 'SP_RENAME' SQL Server Management Studio says the error is on SP_RENAME NOTE: I'm open to other options…
Eric Francis
  • 23,039
  • 31
  • 88
  • 122
4
votes
1 answer

SP_RENAME causing 'invalid column name' issue

I say 'issue' because it's not breaking anything, it's merely a small thing I've noticed in SSMS. I run the following: SP_RENAME 'MyTable.OldName', 'NewName' , 'COLUMN' And then type the following in SSMS: SELECT [NewName] FROM MyTable; The…
user1017882
2
votes
2 answers

sp_rename Procedure with a Variable Column Name

I am trying to use the sp_rename stored procedure with a variable since I do not have control over the source (an Excel file that changes the column name to have a date). I drop a table, and then import that table. I then want to change the column…
Zeus
  • 21
  • 2
2
votes
1 answer

How do I find Stored Procedures with wrong text in syscomments

There appears to be several stored procedures that were renamed with sp_rename, causing the syscomments to be left with the old proc name instead of the new proc name. Thus, my db transfers are failing to transfer correctly. Is there a way to find…
CaffGeek
  • 21,856
  • 17
  • 100
  • 184
1
vote
2 answers

How to write correct syntax to rename SQL Server database table from C# code?

I'm coding in C# in ASP.NET environment and I need to write a function that takes SQL Server database table and gives it another name. So from SQL standpoint I need to do this: EXEC sp_rename 'OldTableName', 'NewTableName'; But the problem is that…
ahmd0
  • 16,633
  • 33
  • 137
  • 233
1
vote
2 answers

How to check if sp_rename is done successfully?

I am running the following query: SELECT * INTO dbo.2015_10_2_cs FROM dbo.2015_10_2 IF NOT EXISTS (SELECT type FROM sys.indexes WHERE object_id = object_id('dbo.2015_10_2_cs') AND NAME ='cci' AND type = 5) BEGIN CREATE CLUSTERED COLUMNSTORE…
alexithymia
  • 317
  • 2
  • 5
  • 18
1
vote
4 answers

Is there any major issue in using EXEC sp_rename '', ''?

I recently used - EXEC sp_rename '', '' to rename an existing table and want to execute the same on one of our live server. Is there any issue in using this procedure to rename a table?. I am asking this…
RAM
  • 856
  • 1
  • 8
  • 27
1
vote
1 answer

How to change a constraint name and schema on Sql Server

I just moved my Member table from MRK schema to GNR. I previously had the script below to set its primary key: If not Exists (select 1 from sys.objects where name = 'PK_MRK_Member' ) ALTER TABLE…
Yalda
  • 680
  • 1
  • 18
  • 39
1
vote
1 answer

Error altering table name MSSQL

Wanted to see if I could get some help concerning altering and renaming tables in MSSQL Server 2008. I am getting an error message on the sp_name syntax and maybe I am doing something wrong? -- Archives data existing one week ago and then…
SRahmani
  • 348
  • 1
  • 5
  • 17
0
votes
1 answer

How to combine an update and sp_rename in SQL Server database

I have a SQL Server database employeedb and table employee with column EmployeeID whose value I need to update and simultaneously rename that column. EmployeeID ----------- 83456785647 I need to add a '-' 2 digit places from the end and rename…
GKC
  • 447
  • 4
  • 10
0
votes
1 answer

How to rename a table that has ".csv" in the name

I have several tables whose names end with .csv. I.e. schema.table1.csv, schema.table2.csv. How can I remove the .csv or rename them without the offending characters? Per this SO question I tried this: exec sp_rename @objname =…
marky
  • 4,878
  • 17
  • 59
  • 103
0
votes
2 answers

EXEC sp_rename stop after several times in a while loop

I try to rename my column name with the firt row of my table. (I know, it do not make sense 'a first row without order by' in SQL, but I have to do this for my test). So, I wan't to search dynamically my old and my new column names to execute…
Michiyo
  • 29
  • 7
0
votes
2 answers

Change multiple table names in SQL Server using sp_rename dynamically

I'm trying to change a series of table names in Microsoft SQL Server 2017 Standard edition using Microsoft SQL Server Management Studio 2018. The code I've been transmitting is based on the following code: use DatabaseX declare @RunRW…
MarJer
  • 87
  • 2
  • 9
0
votes
1 answer

SQL Server - sp_rename to change table name

I'm trying to rename a table using sp_rename but I am getting the following error when executing the query: DECLARE @DateValue INT SET @DateValue = CONVERT(VARCHAR(8), GETDATE()-1, 112) DECLARE @ArchiveTableName VARCHAR(255) SET …
SQLseed
  • 13
  • 5
0
votes
3 answers

SQL Server - rename column within stored procedure with different databases

I have searched and searched and cannot work out how to resolve my problem. I am actually not sure it is possible but thought I'd post here and check. The issue: I have a stored procedure where I make the following call (there are 2 because I was…
1
2