views:

91

answers:

4
ALTER TABLE Physician 
Modify (RefLastName nvarchar(500),
RefFirstName nvarchar(500));

Getting Incorrect syntax error...

+1  A: 

Are you adding columns or changing the size?

You might first try looking up alter table in BOL and then come back here if that doesn't help.

HLGEM
+3  A: 

The way you use ALTER TABLE is not like CREATE TABLE. You mention changes to the table elements rather than specifying all columns from scratch. Like:

ALTER TABLE TableName
ADD LastName NVARCHAR(100) NOT NULL
Mehrdad Afshari
A: 

What is your syntax error ?

I looked at http://www.techonthenet.com/sql/tables/alter%5Ftable.php

Maybe try with:

ALTER TABLE Physician 
Modify (RefLastName varchar2(500),
        RefFirstName varchar2(500));
Joy Dutta
Looks like oracle syntax...he didn't specify the server type
Broam
No actually i have no problem updating size of column using ALter Table and Alter column statment directly in MSSMS. But i am trying to update multiple columns using c# code (SqlCommand).
Novice
+1  A: 

I'm not sure what you're trying to do. Are you changing the size? If so, this is enough:

ALTER TABLE Physician ALTER COLUMN RefLastName nvarchar(500)

GO

ALTER TABLE Physician ALTER COLUMN RefLastName nvarchar(500)

GO

(You may need to force a rebuild of indexes.)

Broam
Yes I am trying to change the column size from c# code using SqlCommand.
Novice
Oke. My problem is i am updating column size using c# code. If i use above statement without Go Statment, SqlCommand (cmd.ExuecteNonQuery) updates the column size but returns -1. If i use Go Statment, it gives Incorrect Syntax near 'Go'. I dont know if you can help me about this using c# code. If you want i can paste my c# code as well.
Novice
It's OK that ExecuteNonQuery returns -1. That's normal. From MSDN: "For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. [...] For all other types of statements, the return value is -1."
Jason Orendorff
Why are you using C# code? This only needs to be run once, unless you're writing a utility to update a database. "GO" has no place in SQL queries run programmatically; it's to tell the SQL interpreter that the next query has nothing to do with the one above it.Instead of using "GO" you should issue two separate queries, one per column.
Broam