?
Solved

How do I add new columns to a SQL table via script

Posted on 2007-10-01
5
Medium Priority
?
857 Views
Last Modified: 2008-01-09
Experts,

I new to sql server 2005. I am developing a db locally and wanted to push a script that copies table design changes over to the production environment. I tried using a script like the one below using the built-in script generator, but I get an error when using it.
----
Msg 102, Level 15, State 1, Line 21
Incorrect syntax near '<'.
----
What's the easiest way to get this accomplished?

Thanks,
HT

==========================================
INSERT INTO [ht-cms-shell].[dbo].[CN_CLIENT]
           ([CN_START_DATE]
           ,[CN_EXP_DATE]
           ,[GF_ID]
           ,[TC_ID]
           ,[CN_ACCOUNTING_ID])
     VALUES
           (<CN_START_DATE, datetime,>
           ,<CN_EXP_DATE, datetime,>
           ,<GF_ID, decimal(18,0),>
           ,<TC_ID, decimal(18,0),>
           ,<CN_ACCOUNTING_ID, nvarchar(25),>)
0
Comment
Question by:htamraz1
5 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 19991913
Use the import/export wizard provided by SQL Server 2005
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 19991979
best and easiest option, is to use some thir party db compare tools like red gate's sql compare, which will give you the script to be applied into the production server comparing both these schemas

U can download the 14  days trial version from red-gate.com
0
 
LVL 18

Expert Comment

by:Yveau
ID: 19993046
The script you posted is something the -- once the syntax is correct -- will insert a record into the table CN_CLIENT ... that is ... it is not adding a column to any table. That would be:

alter table add column [Column1] integer
... or something similar

Hope this helps ...
0
 
LVL 18

Expert Comment

by:Yveau
ID: 19993099
It is *** VERY *** good practice to script out your datamodel modifications (Database Definition Language = DDL), so you can use that DDL later for deployment to other environments. So develop them in the development environment and rerun the script when deploying to Test, Accept and Production environments !

Third party tools are good, ... as long as they provide you the script !!! Don't go 'clicking' the modifications on each and every server or database ... it's the famous accident waiting to happen. ... and it WILL happen on the production environment :-) ... Murphy loves databases as well :-)

hope this helps ...
0
 

Author Comment

by:htamraz1
ID: 19993557
Thanks all. Let me try your suggestions and we'll be back with my accept or request for additional clarification.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question