Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append new column via a script

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
Hello All,

I have added a few new columns to a SQL table during the development cycle and now have to create a script that accomplishes the same on my client's machine. I will not be there when this occurs, so it has to occur seamlessly.

how do I append columns to a Table using T-SQL (in a script) ?

Thanks !

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Is this what you are looking for:
Code:
ALTER TABLE tablename ADD columnname datatype

ex: ALTER TABLE myTable ADD newColumn VARCHAR(10) NULL

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Yes !

I created a simple script with a line that looks like this:

Code:
osql -UAdminAccnt -PPassword -dDatabaseName -Q"ALTER TABLE myTable ADD newColumn VARCHAR(10) NULL"

and gave it a .bat file extension. It **SEEMS** to execute OK, but my app keeps barfing with "Invalid Column Name newColumn". Am I giving my file the right file extension, and if not, where should this file be executed from ?

Thansk !

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
I don't know about having a .bat extension. You should just be able to run the script as it is in the code window.

I use a SQL Server query window and run the T-SQL, so I'm not sure what needs done to run an osql command from an app.

One thing to check is the schema being used. Is the table created in the dbo schema (dbo.tablename). If not, then your app will need to preface any commands with the proper schema name -for example: Chew.tablename

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
I usually put my query into a .sql file then launch the .sql file with a .bat file like

osql -U sa -P password -i c:\query.sql

Simi
 
Thanks, SQLBill / Simian ! I'll let you know what works.

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top