如何创建一个表然后提交然后插入然后提交和删除表?

时间:2013-05-28 14:46:17

标签: sql insert commit firebird2.5 sql-drop

您好我在提交数据库时遇到问题。我是Firebird SQL的新手。但我有一个查询,创建一个表,然后提交它,然后插入它,提交它,查看数据,删除表,然后再次提交它。我试图动态地执行此操作,我可以按下执行按钮一次,然后它就会完成。有没有办法做到这一点?这是查询。

create table bp_customCollections(
       part_number varchar(255)
       ,part_description varchar(255)
       ,guided_reading_level varchar(255)
       ,lexile_level varchar(255)
       ,nonfiction_fiction varchar(255)
       ,on_hand varchar(255)
       ,default_vendor varchar(255)
       ,language varchar(255)
       ,product_price varchar(255)
       )

commit

insert into bp_customcollections(part_number, part_description,guided_reading_level,lexile_level,nonfiction_fiction, on_hand, default_vendor,language,product_price)
SELECT DISTINCT
part.num
,part.description
,COALESCE(grlmin.info,'Undefined')
,getLexile.lexile_level
,COALESCE(fnf.info,'')
,SUM(tag.qty)
,vendor.name
,customvarcharlong.info
,cast(product.price as decimal(10,2))

FROM PART

LEFT JOIN customset AS grlmin ON grlmin.recordid = part.id AND grlmin.customfieldid = 51 -- guided reading level minimum
LEFT JOIN getLexile on getLexile.lexile_partid = part.id and getLexile.lexile_partid = 61 -- lexile level
LEFT JOIN vendorparts on vendorparts.partid = part.id
LEFT JOIN vendor on vendor.id = vendorparts.vendorid
LEFT JOIN customset AS fnf on fnf.recordid = part.id AND fnf.customfieldid = 47  -- fiction/nofiction
LEFT JOIN tag on part.id = tag.partid
LEFT JOIN customvarcharlong on customvarcharlong.recordid = part.id and customvarcharlong.customfieldid = 56 -- language
LEFT JOIN product on product.partid = part.id
LEFT JOIN customset as resourceType on resourcetype.recordid = part.id
where vendorparts.defaultflag = 1
and resourcetype.info = 'Book'
GROUP BY part.num,part.description, COALESCE(grlmin.info,'Undefined'), COALESCE(fnf.info,''),getLexile.lexile_level, vendor.name, customvarcharlong.info,product.price
HAVING SUM(tag.qty) > 0

commit


select * from bp_customcollections
order by part_number

drop table bp_customCollections
commit

1 个答案:

答案 0 :(得分:1)

创建视图,然后在需要时从中进行选择会不会更容易吗?

create view vw_customCollections as
SELECT DISTINCT
part.num
,part.description
,COALESCE(grlmin.info,'Undefined')
,getLexile.lexile_level
,COALESCE(fnf.info,'')
,SUM(tag.qty)
,vendor.name
,customvarcharlong.info
,cast(product.price as decimal(10,2))
FROM PART
LEFT JOIN customset AS grlmin ON grlmin.recordid = part.id AND grlmin.customfieldid = 51 -- guided reading level minimum
LEFT JOIN getLexile on getLexile.lexile_partid = part.id and getLexile.lexile_partid = 61 -- lexile level
LEFT JOIN vendorparts on vendorparts.partid = part.id
LEFT JOIN vendor on vendor.id = vendorparts.vendorid
LEFT JOIN customset AS fnf on fnf.recordid = part.id AND fnf.customfieldid = 47  -- fiction/nofiction
LEFT JOIN tag on part.id = tag.partid
LEFT JOIN customvarcharlong on customvarcharlong.recordid = part.id and customvarcharlong.customfieldid = 56 -- language
LEFT JOIN product on product.partid = part.id
LEFT JOIN customset as resourceType on resourcetype.recordid = part.id
where vendorparts.defaultflag = 1
and resourcetype.info = 'Book'
GROUP BY part.num,part.description, COALESCE(grlmin.info,'Undefined'), COALESCE(fnf.info,''),getLexile.lexile_level, vendor.name, customvarcharlong.info,product.price
HAVING SUM(tag.qty) > 0

然后:

select *
from   vw_customCollections
order by  part_number