MSSQL SQL查询的的问题2?如数据库表为
id name age
1 1 1
2 2 2现在相根据数据库的记录插入一条记录
如插入3,1,3
如name重复则不插入用SQL怎么实现
要求:不能用存诸过程,参数,事务...只能用SQL语句
能实现吗?
id name age
1 1 1
2 2 2现在相根据数据库的记录插入一条记录
如插入3,1,3
如name重复则不插入用SQL怎么实现
要求:不能用存诸过程,参数,事务...只能用SQL语句
能实现吗?
解决方案 »
- 请前辈指导日期型的表达方式?先感谢了!
- 一个简单的特殊排序问题。
- 一条查询select的问题?
- SQLSetPos执行批量添加
- 求文件与数据库导入工具
- 如何统计个数?
- 【求助】sql server 2000中, 单引号与双引号的区别
- 用ODBC連sql調用存儲過程時的小問題,謝謝大寫指點.
- 奇怪,这样的语句在ACCESS是能通过,却在MSSQL里不行了,提示“没有为第 2 列(属于 'AA')指定列。”
- 将节点1的服务移动到节点2后 数据库服务起不来。initerrlog: 无法打开错误日志文件。操作系统错误 = 3(系统找不到指定的路径。)。
- 为什么有时会从表保存了而主表却没有保存相应的记录?
- 小问题,请教
if not exists(select 1 from tableA where [name] = '3' )
insert into tableA (id,name,age) select '3','3','1'
insert into tb
select top 1 3,'1',3 from tb t where not exists(
select * from tb where name='1')
select top 1 3,'1',3 from tb t where not exists(
select * from tb where name='1')
insert tb select top 1 3,1,3 from tb where not exists(select 1 from tb where name=1)
insert @t select 1, 1, 1
insert @t select 2, 2, 2
declare @i int , @name int,@age int
set @i=3 set @name=1 set @age=3
insert @t select @i,@name,@age where @name not in(select name from @t)
select * from @t
/*id name age
----------- ----------- -----------
1 1 1
2 2 2(所影响的行数为 2 行)*/
table:是你的表
TableA: 数据来源表。insert into table(id,name,age)
select id,name,age
from TableA
where name
not in(select name from table)