0

I want to add one column to an existing table in C#, if it doesn't already exist. I know I have to use an 'alter table' command.

But I am not able to fire that command in my C# code.
How can I do?

I'm using Visual Studio 2010 and Sql Server 2008.

3

1 Answer 1

0

this :

Use [DatabaseName]
Go
if Not exists( Select * from sys.columns As clm
                where clm.object_id = OBJECT_ID(N'[TableName]')
                And clm.name = N'[ColumnName]'
              )
Begin

    Alter Table TableName
    Add ColumnName DataTypeName

End
Sign up to request clarification or add additional context in comments.

1 Comment

thnx user3540365, Rajesh and raj. I appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.