全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3933
推到 Plurk!
推到 Facebook!

如何改變paradox primary 的欄位大小

 
ad
一般會員


發表:1
回覆:0
積分:0
註冊:2002-03-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-03-11 07:45:05 IP:163.17.xxx.xxx 未訂閱
我有一個資料表:student 其中guyid為primary key (字元型態) 其大小原本為6 我想將它的大小改為10 如何用程式做到呢?
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-03-11 09:28:46 IP:61.219.xxx.xxx 未訂閱
引言: 我有一個資料表:student 其中guyid為primary key (字元型態) 其大小原本為6 我想將它的大小改為10 如何用程式做到呢?
用人工改可用Database Desktop工具可成功修改,且原資料會留 用程式改的話應是採用TQuery元件下SQL為Alter Table ... 我曾試過加一個欄位在paradox可以成功 ALTER TABLE STUDENT ADD STUDENT_MEMO CHAR(20) 但用 ALTER TABLE STUDENT MODIFY GUYID CHAR(10)會出現不認得MODIFY 再試INTERBASE也不行 可能要用BDE提供的內部Function處理,待我試過...網友們一起來想想
------
~~~Delphi K.Top討論區站長~~~
BEELIN
一般會員


發表:9
回覆:21
積分:11
註冊:2002-03-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-03-11 12:25:33 IP:61.219.xxx.xxx 未訂閱
引言: 我有一個資料表:student 其中guyid為primary key (字元型態) 其大小原本為6 我想將它的大小改為10 如何用程式做到呢?
PARADOX用TQuery只接受Alter Table xxx ADD/DROP兩種 可以考慮用: 1.ALTER TABLE STUDENT ADD GUYID2 CHAR(10) 2.UPDATE STUDENT SET GUYID2=GUYID 3.ALTER TABLE STUDENT DROP GUYID 4.ALTER TABLE STUDENT ADD GUYID CHAR(10) 5.UPDATE STUDENT SET GUYID=GUYID2 6.ALTER TABLE STUDENT DROP GUYID2 這樣會不會太笨了,還有Primary Key是否還存在? 大家一起來傷腦筋看看???
天外來客
初階會員


發表:22
回覆:199
積分:44
註冊:2001-11-27

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-03-13 10:31:44 IP:202.123.xxx.xxx 未訂閱
從兩個層面去看。第一是不同的資料庫所使用的語法是不盡相同的, 特別是 DDL 部份, 例如 Admin 所用的 Modify 子句, 是在 Oracle 上行得通的, 但在 Interbase 上就不行, Interbase 上的句法我忘記了, 要查一下, SQL Server 又是另一個樣子。第二個層面是 Database Connectivity Tool 的考慮(擔心)問題, 也就是說, 即是資料庫支援的 DDL, Connectivity 不一定支援, 特別以 DDL 而言。因為 DML 都是大家常用的部份, 自然做得比較完美, 當然也不一定的。例如我使用 PostgreSQL 時候, 就因為沒看清楚文件, 不知道其 ODBC Driver, 尚未支援 Money data type 而誤用了, 因而麻煩了一陣子。所以用任何的 DB Connectivity 來操作 DDL 便更該有披荊斬棘的心理準備了。
LYW
一般會員


發表:9
回覆:32
積分:8
註冊:2002-03-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-03-14 01:28:01 IP:61.216.xxx.xxx 未訂閱
引言: 我有一個資料表:student 其中guyid為primary key (字元型態) 其大小原本為6 我想將它的大小改為10 如何用程式做到呢?
提供下列方法重建Primary Key,可試試....
procedure createTempTable;
var
Temp:TTable;
begin
Temp:=TTable.Create(Self);
with Temp do
begin
DatabaseName:=''MyDB'';
TableName:=''Temp'';
TableType:=ttParadox;//類型可為ttASCII,ttParadox,ttDbase
with FieldDefs do  //Table schema...
begin
  Clear;
  Add(''strTT'',ftString,10,false);
  Add(''fltAAA'',ftFLOAT,0,false);
  Add(''bnYesNo'',ftBoolean,0,false);
  Add(''sintQTY'',ftSmallint,0,false);
// ........ ==> Add Other Fields...
end;
with IndexDefs do //Index 
begin
 Clear;
 Add(''Primary'',''strTT'',[ixPrimary,ixUnique]);
  // ........ ==> Add Other Indexes...
end;
CreateTable; // ==> Create Table procedure;
end;
end;
scottliou
版主


發表:16
回覆:56
積分:47
註冊:2002-03-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-03-14 10:32:14 IP:61.70.xxx.xxx 未訂閱
我想要修改欄位大小基本上就是非常的麻煩,而且也必須考慮本身 程式的寫法是否容許可變性的欄位,所以執行此作業應是等級非常 高的權限,大部份不可能在使用者介面上修改,所以如果可以最好 使用資料庫本身附的Utility來修改較好 1. MS SQL Server : Enterprise Manager 2. Interbase : IB Console 3. MySQL : MySQL Front...等等 對於上面大家所提供的方法我覺得較安全的作是 先Create一個table 然後再Insert 過來這樣才不會因為指令錯誤而導致....... 給大家做個參考 ~~~~~~~~~~~~~~~~ 有夢想最美......
------
~~~~~~~~~~~~~~~~
有夢想最美......
LYW
一般會員


發表:9
回覆:32
積分:8
註冊:2002-03-08

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-03-17 15:32:26 IP:61.216.xxx.xxx 未訂閱
引言: 我有一個資料表:student 其中guyid為primary key (字元型態) 其大小原本為6 我想將它的大小改為10 如何用程式做到呢?
從另一處POST的範例,請試試!
Example 3: Alter a field in a Paradox or dBASE table.
This example will alter an existing field in a Paradox or dBASE table. NOTE: You must fill in all options in the ChangeRec with 0 or '''' if the option is not used in the restructure. FillChar can be used to do this:      Fillchar(MyChangeRec, sizeof(MyChangeRec), 0);    This example uses the following input:      ChangeField(Table1, Table1.FieldByName(''FOO''), MyChangeRec)    ChangeRec is defined as follows:    type      ChangeRec = packed record
    szName: DBINAME;
    iType: Word;
    iSubType: Word;
    iLength: Word;
    iPrecision: Byte;
    end;    The function is defined as follows:    procedure ChangeField(Table: TTable; Field: TField; Rec: ChangeRec);    var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;
  pFields: pFLDDesc;
  pOp: pCROpType;
  B: Byte;
begin
  // Initialize the pointers...
  pFields := nil;
  pOp := nil;
  // Make sure the table is open exclusively so we can get the db handle...
  if not Table.Active then
    raise EDatabaseError.Create(''Table must be opened to restructure'');
  if not Table.Exclusive then
    raise EDatabaseError.Create(''Table must be opened exclusively''            ''to restructure'');
  Check(DbiSetProp(hDBIObj(Table.Handle), curxltMODE, Integer(xltNONE)));
  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));
  // Make sure the table is either Paradox or dBASE...
  if (Props.szTableType <> szPARADOX) and (Props.szTableType <> szDBASE) then
    raise EDatabaseError.Create(''Field altering can only occur on Paradox''  
      '' or dBASE tables'');      // Allocate memory for the field descriptor...
  pFields := AllocMem(Table.FieldCount * sizeof(FLDDesc));
  // Allocate memory for the operation descriptor...
  pOp := AllocMem(Table.FieldCount * sizeof(CROpType));
  try
    // Set the pointer to the index in the operation descriptor to put
    // crMODIFY (This means a modification to the record is going to happen)...
    Inc(pOp, Field.Index);
    pOp^ := crMODIFY;
    Dec(pOp, Field.Index);
    // Fill the field descriptor with the existing field information...        Check(DbiGetFieldDescs(Table.Handle, pFields));
    // Set the pointer to the index in the field descriptor to make the
    // midifications to the field
    Inc(pFields, Field.Index);
    // If the szName portion of the ChangeRec has something in it, change it...
    if (Length(Rec.szName) > 0) then
      pFields^.szName := Rec.szName;
    // If the iType portion of the ChangeRec has something in it, change it...
    if (Rec.iType > 0) then          pFields^.iFldType := Rec.iType;
    // If the iSubType portion of the ChangeRec has something in it, change it...
    if (Rec.iSubType > 0) then
      pFields^.iSubType := Rec.iSubType;
    // If the iLength portion of the ChangeRec has something in it, change it...
    if (Rec.iLength > 0) then
      pFields^.iUnits1 := Rec.iLength;
    // If the iPrecision portion of the ChangeRec has something
    // in it, change it...
    if (Rec.iPrecision > 0) then          pFields^.iUnits2 := Rec.iPrecision;
    Dec(pFields, Field.Index);
    for B := 1 to Table.FieldCount do begin
      pFields^.iFldNum := B;
      Inc(pFields, 1);
    end;
    Dec(pFields, Table.FieldCount);        // Blank out the structure...
    FillChar(TableDesc, sizeof(TableDesc), #0);
    //  Get the database handle from the table''s cursor handle...
    Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));        // Put the table name in the table descriptor...
    StrPCopy(TableDesc.szTblName, Table.TableName);
    // Put the table type in the table descriptor...
    StrPCopy(TableDesc.szTblType, Props.szTableType);
    // The following three lines are necessary when doing any field restructure
    // operations on a table...        // Set the field count for the table
    TableDesc.iFldCount := Table.FieldCount;
    // Link the operation descriptor to the table descriptor...        TableDesc.pecrFldOp := pOp;
    // Link the field descriptor to the table descriptor...
    TableDesc.pFldDesc := pFields;
    // Close the table so the restructure can complete...
    Table.Close;
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, False));
  finally
    if (pFields <> nil) then
      FreeMem(pFields);
    if (pOp <> nil) then          FreeMem(pOp);
  end;
end;
系統時間:2024-03-28 20:42:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!