Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 add new columns to create script of a database

Author  Topic 

praneeth n
Starting Member

2 Posts

Posted - 2014-12-22 : 04:31:18
Hi
Am a fresher and I got a scenario like i have to take create script of some tables of a database in sql server and I generated script to them and i have to add four new columns to the script and have to delete 2 columns from existing script for multiple tables at a time. It will take more time to do them individually.
Is there any way to do this at a time and with in short period of time????

can you guys please help me

Thanks in advance

Praneeth N

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-22 : 09:34:32
THis can probably be done in an appropriate query. However, you need to post what you have so far, or at least some samples of the script you want to add/delete columns to.

Note that by the time we're done here, you probably could do it by hand.
Go to Top of Page

praneeth n
Starting Member

2 Posts

Posted - 2014-12-23 : 02:13:16
Hi Gbritton
thanks for the response
suppose i have tables like code_1, code_2........code_n, for all these tables have columns like pk_code1,code_value,Description, from_date, to_date.....and pk_coden,code_value,description,from_date, to_date and i have to insert 4 new columns in between pk_code1 and code_value and i have to delete from_date&to_date and replace pk_code1 with code1_id......pk_coden with coden_id
and the create script is like
create table code1(pk_code1 int not null,code_value int not null,descrpition varchar(100) not null,from_date datetime not null,to_date datetime not null,)
have to get the above script as follows
create table code1
(code1_id int not null,sys_id int not null,sys_desc varchar(100) NOT NULL,time_stamp datetime not null,indicator varchar(10) not null, code_value int not null,descrpition varchar(100) not null)
like that i have to modify tables from code1 to coden. and the no of tables are more than 500

thanks in advance

Praneeth N
Go to Top of Page

desperadomar
Starting Member

3 Posts

Posted - 2015-01-07 : 05:11:36
quote:
Originally posted by praneeth n

Hi Gbritton
thanks for the response
suppose i have tables like code_1, code_2........code_n, for all these tables have columns like pk_code1,code_value,Description, from_date, to_date.....and pk_coden,code_value,description,from_date, to_date and i have to insert 4 new columns in between pk_code1 and code_value and i have to delete from_date&to_date and replace pk_code1 with code1_id......pk_coden with coden_id
and the create script is like
create table code1(pk_code1 int not null,code_value int not null,descrpition varchar(100) not null,from_date datetime not null,to_date datetime not null,)
have to get the above script as follows
create table code1
(code1_id int not null,sys_id int not null,sys_desc varchar(100) NOT NULL,time_stamp datetime not null,indicator varchar(10) not null, code_value int not null,descrpition varchar(100) not null)
like that i have to modify tables from code1 to coden. and the no of tables are more than 500

thanks in advance

Praneeth N




Since you have the script edit it! but also you should change the renamed or deleted column names in other parts of the script if referenced.

I prefer renaming,deleting ,creating new columns(if no constraints are defined) before creating the scripts like,

To delete a particular column

ALTER TABLE code1 DROP COLUMN From_date

for rename you can use sp_rename system stored procedure

for adding new column

ALTER TABLE code1 ADD COLUMN New_colunmname
Go to Top of Page
   

- Advertisement -