Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Working with Computed column in SQL Server 2000

Total Hit ( 1541)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


There are restriction for ALTER COLUMN, documented in Books Online (see end
of this post). Depending on your particular situation, you need to DROP
INDEX, ALTER TABLE... DROP CONSTRAINT etc.

The altered column cannot be:

 a) A column with a text, image, ntext, or timestamp data type.


 b) The ROWGUIDCOL for the table.


 c) A computed column or used in a computed column.


 d) A replicated column.


 e) Used in an index, unless the column is a varchar, nvarchar, or
varbinary data type, the data type is not changed, and the new size is equal
to or larger than the old size.


 f) Used in statistics generated by the CREATE STATISTICS statement. First
remove the statistics using the DROP STATISTICS statement. Statistics
automatically generated by the query optimizer are automatically dropped by
ALTER COLUMN.


 g) Used in a PRIMARY KEY or [FOREIGN KEY] REFERENCES constraint.


 h) Used in a CHECK or UNIQUE constraint, except that altering the length
of a variable-length column used in a CHECK or UNIQUE constraint is allowed.


 i) Associated with a default, except that changing the length, precision,
or scale of a column is allowed if the data type is not changed.

Click here to copy the following block
--Drop table Orders
--go

Create table Orders
(
OrderId int NOT NULL PRIMARY KEY
,CustomerId int NOT NULL
,ProductId int NOT NULL
,Quantity int DEFAULT(1)
,UnitPrice money
--, Total as (Quantity * UnitPrice)
)

go

--// Add new Computed Column
Alter table Orders
ADD Total as (Quantity * UnitPrice)/100
go


--//Note: To alter a computed column drop the column and add again

--// ****** Error *************************
--Alter table Orders
-- Alter Column Total (Quantity * UnitPrice)
--/////////////////////////////////////////

Alter table Orders
Drop column Total

go

Alter table Orders
ADD Total as (Quantity * UnitPrice)
go


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.