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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add into every type user

Status
Not open for further replies.

jamert

Programmer
Dec 9, 2007
80
CA
Hi i have 10 tables that all have an int, no relationships, column called MemberID. I would like to add memberID from 1 to 2000 in all 10 tables. Is there a way to do this while loop based for all tables of type 'user' ?

thanks
 
You could use dynamic sql and execute sp_foreachtable, but with ten tables, it would probably be faster to just copy and paste an insert statement ten times.

Code:
DECLARE @i INT
SELECT @i = 1

WHILE @i <= 2000
BEGIN
  INSERT INTO Table1 (MemberID) SELECT @i
  INSERT INTO Table2 (MemberID) SELECT @i
  etc...
  SELECT @i = @i + 1
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top