How to add a row for all rows in another table in SQL Server

I am not the best in SQL. I have a table with approximately 20,000 users (rows). I have another table that I would like to add for each user using my username. Is this possible using only SQL?

I could just go into the application (written in C #) and use linq to pull out all users, iterate over them and add a line for each user. I'm just wondering if there is a way to do this directly in SQL.

TABLE Users Username (varchar) etc etc TABLE ChatChannels Username (varchar) ChannelName (varchar) 

I would like to add one row in ChatChannels for each user in Users, using the username to populate the Username column in ChatChannels.

+6
sql sql-server-2008 ssms
source share
1 answer
 insert into chatchannels (Username, ChannelName) select username, 'NewChatChannel' from users 

Inserts one line for username in users , and the channel name is set to "NewChatChannel".

+8
source share

All Articles