| Author |
Topic |
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-17 : 19:28:10
|
| CREATE TABLE TableMaster( table_name VARCHAR(500))INSERT INTO TableMaster (table_name) VALUES ( 'datatable1' ) INSERT INTO TableMaster (table_name) VALUES ( 'datatable2' ) ..INSERT INTO TableMaster (table_name) VALUES ( 'datatable10' ) datatable1, datatable2 .. are physical tables IN DATABASE.TableMaster will KEEP growing WITH TABLE names IN DATABASE.Assuming each TABLE has COLUMN number. i need TO UPDATE this number FOR ALL tables IN TableMasterhow i can do without CURSOR.?mk_garg |
|
|
dexter.knudson
Constraint Violating Yak Guru
260 Posts |
Posted - 2008-09-17 : 22:36:57
|
| Is there a reason why you don't get this info from INFORMATION_SCHEMA.tables ORSELECT *FROM sysobjectswhere type = 'U' ? |
 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-17 : 22:42:35
|
| Yes TableMaster will store tables i need to update.even if i get it from INFORMATION_SCHEMA.table, i can get list of tables.Then i need to update listed table.is their any way to update all tables in one go instead of using cursor to update 1 at a time. Thanksmk_garg |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 00:16:43
|
quote: Originally posted by mk_garg20 Yes TableMaster will store tables i need to update.even if i get it from INFORMATION_SCHEMA.table, i can get list of tables.Then i need to update listed table.is their any way to update all tables in one go instead of using cursor to update 1 at a time. Thanksmk_garg
update each tables? with what data? |
 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-18 : 00:32:44
|
| just update number = number * 2 will do the job..thanksmk_garg |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 00:37:40
|
quote: Originally posted by mk_garg20 just update number = number * 2 will do the job..thanksmk_garg
do all tables have the number column? |
 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-18 : 00:44:59
|
| yesmk_garg |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 01:00:51
|
quote: Originally posted by mk_garg20 yesmk_garg
DECLARE @Table varchar(100)SELECT @Table=MIN(TABLE_NAME)FROM INFORMATION_SCHEMA.TABLESWHILE @Table IS NOT NULLBEGINSET @Sql='Update '+@Table + ' SET number=number * 2'EXEC (@Sql)SELECT @Table=MIN(TABLE_NAME)FROM INFORMATION_SCHEMA.TABLESWHERE TABLE_NAME>@TableEND |
 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-18 : 01:25:00
|
| OK thanksAny other solution to avoid dynamic sql.Thanksmk_garg |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 01:53:41
|
quote: Originally posted by mk_garg20 OK thanksAny other solution to avoid dynamic sql.Thanksmk_garg
EXEC sp_MSforeachtable 'UPDATE ? SET number=number*2' |
 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2008-09-18 : 01:57:50
|
| Thanksmk_garg |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-18 : 03:54:31
|
| Make use of the result and runSELECT 'Update '+TABLE_NAME+' set number=number * 2'FROM INFORMATION_SCHEMA.TABLESMadhivananFailing to plan is Planning to fail |
 |
|
|
|