create table sale
( 货号 int not null,
品名 char(20) not null,
数量 int not null,
单价 char(20) not null,
总价 as 数量*单价,              --计算列
primary key(货号)
)
go

解决方案 »

  1.   

    create table sale
    ( 货号 int not null,
    品名 char(20) not null,
    数量 int not null,
    单价 money not null,   --money数据类型
    总价 as 数量*单价,                --计算列
    primary key(货号)
    )
    go
    create table goods
    ( 编号 int not null,
    品名 char(20) not null,
    库存量 int not null,
    进价 money not null,
    售价 money not null,
    供货商编号 int not null,
    primary key (编号)
    )--对于数值型数据字段,不需要用单引号
    insert into goods values('1','康师傅橙汁',56,3.7,5.6,1);
      

  2.   

    --对于数值型数据字段,不需要用单引号
    insert into goods(编号, 品名,库存量,进价,售价,供应商编号) values('1','康师傅橙汁',56,3.7,5.6,1);
      

  3.   

    问题(2)单价改成money数据类型,如何使用?---------------------------------就和使用整数类似,只不过有小数罢了,对于数值型字段insert into语句不需要用单引号insert into sale(货号, 品名,数量,单价,) 
    values(
    '1',
    '康师傅橙汁',
    20, --int
    3.7, --money
    )--如果总价定义为计算列,追加后自动计算总价
      

  4.   

    非常感谢你,希望你能再回答一个问题,好吗?
    我现在想计算出总价这一属性的和,怎么做呢?
    select sum(总价) from sale;
    可以吗?
    得到的值我又能如何保存呢?
    我在Delphi中
    begin
        sqlStr:='select sum(总价) from sale';
        with Query1 do
        begin
            Close;
            SQL.Clear;
            SQL.Add(sqlStr);
            Open;
        end;
        if recordcount<1 then Edit5.Text:='';
    end;
    我不知道从哪里得到查询的值。
    如果可以,能留下你的QQ吗?
    我的QQ:66574049