Breaking News
Loading...
29/05/2014

Alter computed column trong SQL Server

-- Create table
CREATE TABLE Table1 
( Col1 INT, 
  Col2 AS Col1 * 10
);

-- Failed attempt to alter column
ALTER TABLE Table1
 ALTER COLUMN Col2 AS Col1 / 10;
The above script will give following error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword ‘AS’.

The best way to fix this is to drop the column and recreate it.

-- Drop Column
ALTER TABLE Table1
DROP COLUMN Col2;
-- Create Column
ALTER TABLE Table1
ADD Col2 AS Col1/10;

0 comments:

Post a Comment

 
Toggle Footer