Hi All,
Suppose I have created one table say "Customer"
Customer (cust_no, cust_name,cust_address)
I want to change the attribute name "cust_no" to "cust_number".
How to do it using ALTER command.
Pls give me the exact syntax for this.
Regards
Abdul
Hi abdul,
The safest way to do so is using the following:
/* 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.Customer.cust_no', N'Tmp_cust_number', 'COLUMN'
GO
EXECUTE sp_rename N'dbo.Customer.Tmp_cust_number', N'cust_number', 'COLUMN'
GO
COMMIT
(An easy way to generate a script like this yourself is changing the layout through SQL Server Management Studio, right-clicking the table, selecting "design", then making the change, and before doing anything else, clicking the left-most button labelled "Generate change script").
HTH.
Peter
No comments:
Post a Comment