帮我做下数据库编程题,谢谢

帮我做下数据库编程题,谢谢,第1张

创建视图:

create view price_view as

select b.mname as 商场名,a.ino as 商品号,c.iname 商品名 as ,a.price as 价格

from sales a,market b,item c

where a.mno = b.mno and a.ino = c.ino

统计平均售价

select 商品名,avg(价格) as 平均售价 from price_view group by 商品名

编程题1:

procedure TForm1.FormActivate(Sender: TObject)

const MAX_LINE = 100

var i: Integer

begin

  randomize()

  with Canvas do

  begin

    for i := 1 to MAX_LINE do

    begin

      Pen.Color := random(65536)

      LineTo(random(ClientRect.Right-ClientRect.Left),random(ClientRect.Bottom-ClientRect.Top))

      sleep(500)

      Application.ProcessMessages

    end

  end

end

运行结果:

编程题2:

对于数据库的 *** 作可以分为两种方式:

1、用 SQL 语句执行。

示例:

procedure TForm1.btn1Click(Sender: TObject)

begin

  With qry1 do

  begin

   //查询记录

   Close

   SQL.Clear

   SQL.Add('Select * from test_tab')

   Open

   //添加记录

   Close

   SQL.Clear

   SQL.Add('Insert into test_tab Values ("张三","23",#1999/01/01#)')

   ExecSQL

   //删除记录

   Close

   SQL.Clear

   SQL.Add('Delete from test_tab Where name="张三"')

   ExecSQL

   //修改记录

   Close

   SQL.Clear

   SQL.Add('Update test_tab Set age=25 Where name="张三"')

   ExecSQL

  end

end

2、用数据库 *** 作命令执行。

With qry1 do

begin

 //添加记录

  Append

  Fieldbyname('字段名').Value:=值

  post

  //添加记录

  Edit

  Fieldbyname('字段名').Value:=值

  post

  //删除记录

  DeleteRecords(arCurrent)

end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6426431.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-22
下一篇 2023-03-22

发表评论

登录后才能评论

评论列表(0条)

保存