sql问题(30分)

  • 主题发起人 主题发起人 小二郎
  • 开始时间 开始时间

小二郎

Unregistered / Unconfirmed
GUEST, unregistred user!
问题:在表中加字段的时候,在设置类型的时候为什么只能设成是varchar而不能设成
varnumber等等,怎么样在此语句中加入字段的默认值呀?(delphi的数据类型好像和
pascal不一样啊)。还有就是怎么样清除一个表中的所有记录,而不消结构?

query1.SQL.Add('ALTER TABLE 考试表 ADD COLUMN '+edit1.text+' varchar(9)');
 
这里的数据类型不是delphi的而是数据库定义的 如sqlserver,paradox等
1.query1.SQL.Add('ALTER TABLE 考试表 ADD COLUMN '+edit1.text+' varchar(9) DEFAULT ('9952')
');
2.
query.sql.clear;
query.sql.add('delete from tablename');
query.exesql;
 
清除表中所有記錄,設表名為tablename:
1.sql語句:delete from tablename
2.設table表控件連接tablename表,
可以:
table.close;
table.emptytable;
table.open;
 
什么数据库啊,没听过varnumber这种类型哦
 
还以为自己孤陋寡闻~没好意思说~~~
 
小完总是想得出各种办法混分:)
 
:( 你一点都不了解我
 
小完还那么委屈呀
 
用default('0')不好使呀,有没有别的办法了,是不是错了,我想让成绩默认为0分可是
加‘’编不过去,不加编过去了但是不好使。
 
还有就是parodox表中的数据类型都怎么写呀,比如说number型写在程序中就不行啊
还有就是怎么设定小数的位数呀。请赐教
 
使用ttable动建表就行了.
The following example shows how to create a table.

{ Don't overwrite an existing table }

if not Table1.Exists then begin
with Table1 do begin
{ The Table component must not be active }
Active := False;
{ First, describe the type of table and give }
{ it a name }
DatabaseName := 'DBDEMOS';
TableType := ttParadox;
TableName := 'CustInfo';
{ Next, describe the fields in the table }
with FieldDefs do begin
Clear;
with AddFieldDef do begin

Name := 'Field1';
DataType := ftInteger;
Required := True;
end;
with AddFieldDef do begin
Name := 'Field2';
DataType := ftString;
Size := 30;
end;
end;
{ Next, describe any indexes }
with IndexDefs do begin
Clear;
{ The 1st index has no name because it is
{ a Paradox primary key }
with AddIndexDef do begin

Name := '';
Fields := 'Field1';
Options := [ixPrimary];
end;
with AddIndexDef do begin
Name := 'Fld2Indx';
Fields := 'Field2';
Options := [ixCaseInsensitive];
end;
end;
{ Call the CreateTable method to create the table }
CreateTable;
end;
end;//其实就是delphi中的帮助.
 
default 0
怎么不好使?
 
create table不要用number
用 NUMERIC
或者 NUMERIC(s)
或者 NUMERIC(s, p)
 
默认值还是加不上呀?提前
 
怎么加的默认值,报告什么错误?
 
学习。。。。。
 
就是用前面写的用default不报错就是加不上呀
 
多人接受答案了。
 
后退
顶部