Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change a field name 1

Status
Not open for further replies.

zemp

Programmer
Jan 27, 2002
3,301
CA
T-SQL
SQL Server 2000 SP4

I am wondering if it is possible to directly change the name of a field in a table.

I can create a new field, copy the data and then delete the original field. But I don't think that that is a clean way of doing things.

FYI, I am writing a script to update a database.

zemp
 
Here the script SQL Server 2005 generate hwen I rename a column:
Code:
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.ADDSUM.RABDNI', N'Tmp_RABDNI1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.ADDSUM.Tmp_RABDNI1', N'RABDNI1', 'COLUMN' 
GO
COMMIT

AddSum is the name of my Table and RABDNI is old Column Name and RabDni1 is new column name.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks, that was fast and it worked great.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top