本文介紹了根據(jù)另一個表的列值將值插入表中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想根據(jù)輔助表列的所有值將數(shù)據(jù)插入到表中.例如
I would like to insert data into a table based on all the values of a secondary table's column. For example
我有兩張桌子
CREATE TABLE Table1 (
id int identity(1, 1) not null,
FullName varchar(100),
Age int,
CourseID int
)
CREATE TABLE Table2 (
id int identity(1, 1) not null,
Courses int
)
我想執(zhí)行這樣的操作..
I would like to perform something like this ..
insert into Table1 ('Auser',20,'And the list of Courses that I get from Table2')
有沒有辦法在 sql server 中做到這一點?
Is there a way I can do this in sql server ?
推薦答案
那么對于一位新用戶,您想插入所有可用的課程嗎?
So for one new user you want to insert all available courses?
INSERT INTO Table1
SELECT 'Ausser', 20, t2.Courses
FROM Table2 t2;
這是小提琴:http://sqlfiddle.com/#!3/89470/1/0
這篇關于根據(jù)另一個表的列值將值插入表中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!