Friday, March 30, 2012

How to change the Datatype of a column in SQL 7

Hi Everyone,

I am trying to change a column for a table by using Transact-SQL 7

The table name is ActionLog and the column name is ActiveSys

Before change:

ActiveSys datatype char(12)

After change:

ActiveSys datatype varchar(30)

I use this command:

alter table ActionLog alter column ActiveSys varchar(30) not null

but the system keeps giving me this error message:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'column'.

I follow the syntax provide by the MS: (and I search on Google and found none of the standard SQL syntax works.)

Syntax

ALTER TABLE table
{ [ALTER COLUMN column_name
{ new_data_type [ (precision[, scale] ) ]
[ NULL | NOT NULL ]
| {ADD | DROP} ROWGUIDCOL
}
]
| ADD
{ [ <column_definition> ]
| column_name AS computed_column_expression
}[,...n]
| [WITH CHECK | WITH NOCHECK] ADD
{ <table_constraint> }[,...n]
| DROP
{ [CONSTRAINT] constraint_name
| COLUMN column
}[,...n]
| {CHECK | NOCHECK} CONSTRAINT
{ALL | constraint_name[,...n]}
| {ENABLE | DISABLE} TRIGGER
{ALL | trigger_name[,...n]}
}

Can anyone help me? or Point out what is wrong with my code?

Thanks in advance.

dont use the keyword column, just use

alter table ActionLog alter ActiveSys varchar(30) not null

|||Thanks Shyam. I found either your code or my code are wrong. the reason our code does not work because the compatibility issues. before running the code, we should run:

EXEC sp_dbcmptlevel '<Database name>', 70
alter table ActionLog alter ActiveSys varchar(30) not null
EXEC sp_dbcmptlevel '<Database name>', 65

Cheers.

No comments:

Post a Comment