
1、select * into destTbl from srcTbl。
2、insert into destTbl(fld1, fld2) select fld1, 5 from srcTbl。
以上两句都是将 srcTbl 的数据插入到 destTbl,但两句又有区别的:
第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建。
第二句(insert into select from)要求目标表(destTbl)存在,由于目标表已经存在,所以我们除了插入源表(srcTbl)的字段外,还可以插入常量。
拓展资料:结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。sql 语句就是对数据库进行 *** 作的一种语言。
常见语句:
1、更新:update table1 set field1=value1 where 范围。
2、查找:select * from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串)。
3、排序:select * from table1 order by field1,field2 [desc]。
4、求和:select sum(field1) as sumvalue from table1。
5、平均:select avg(field1) as avgvalue from table1。
6、最大:select max(field1) as maxvalue from table1。
7、最小:select min(field1) as minvalue from table1[searator]。
对表1写个添加触发器。create trigger trigger_1on 表1for insert asdeclare @shuxuedeclare @yuwenselect @shuxue=shuxue,@yuwen=yuwen from insertedinsert into 表2 values(@shuxue,@yuwen)。SQL是高级的非过程化编辑语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式,所以具有完全不同底层结构的不同数据库系统可以使用相同的sql语言作为数据输入与管理的接口。
在a表建个触发器就行了大概是这样
create tgigger tr_ins_A ON A
instead of insert
AS
if not exists(select * from inserted where Applicant not in (select Applicant from B))
insert into B
select * from inserted
else
raiserror('not find',16,1)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)