怎样用insert将其它表的值和固定值插入到表?

zhit 2003-09-25 10:10:56
怎样用insert将其它表的值和固定值插入到表?
e.g.
insert table1 (a,b,c,d) values (e,f,g,h)
其中e的值是其它表的值,如table2.e,我应该怎样调用呢?f,g,h是我付的值!怎样解决呢??
...全文
128 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijixin 2004-02-28
  • 打赏
  • 举报
回复
insert into tablename{(column1,column2,...)}
select q_column1,q_column2,... from another tablename
where select_conditions:
CrazyFor 2003-09-26
  • 打赏
  • 举报
回复
insert into exp select a ,1,3,4,"string" from exp2
killxtt 2003-09-26
  • 打赏
  • 举报
回复
可以用这样的方式
insert into exp select a,1,2,3 from exp2
如果直接select常量,则选出来的就是常量
但是不能这样用
insert into exp values((select a from exp2),1,2,3)
会报错说是不能确定select出来的是不是唯一的
westbulls 2003-09-25
  • 打赏
  • 举报
回复
当然可以,楼上的语句没有问题。
welyngj 2003-09-25
  • 打赏
  • 举报
回复
试一下就知道。
create table exp
(a int,
b int,
c int,
d int)
create table exp2
(a int)
insert into exp2 select 1
insert into exp2 select 4
insert into exp select a ,1,3,4 from exp2
select * from exp
zhit 2003-09-25
  • 打赏
  • 举报
回复
但f,g,h不是Table2的,也行吗?
j9988 2003-09-25
  • 打赏
  • 举报
回复
f,g,h=1,2,3
:
insert table1 (a,b,c,d) select e,1,2,3 from table2

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧