Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 5 of 5 total |
How to add a column to an exsiting table programmatically |
Mon, Oct 19 2015 1:14 PM | Permanent Link |
Brian Clingan | Does anyone know how to add a column to a DBISAM table using program code?
|
Mon, Oct 19 2015 1:18 PM | Permanent Link |
Raul Team Elevate | On 10/19/2015 1:14 PM, Max Stewart wrote:
> Does anyone know how to add a column to a DBISAM table using program code? > Yes. Did you look at the manual ? I would suggest start with the "Creating and Altering Tables" section there http://www.elevatesoft.com/manual?action=viewtopic&id=dbisam4&product=rsdelphiwin32&version=10S&topic=Creating_Altering_Tables Raul |
Mon, Oct 19 2015 4:05 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Max,
<< Does anyone know how to add a column to a DBISAM table using program code? >> As Raul suggests, there's an example at that link, specifically this one: The following example shows how to alter the local "customer" table's structure using the AlterTable method without any additional parameters. In this example we want to add a LastSaleAmount (a BCD field) to this table's structure in front of the LastSaleDate field and then add a secondary index on this new LastSaleAmount field to speed up filtering in SQL queries: Customer Table Structure Before Alteration Field # Name DataType Size ---------------------------------------------- 1 CustomerID ftString 10 2 CustomerName ftString 30 3 ContactName ftString 30 4 Phone ftString 10 5 Fax ftString 10 6 EMail ftString 30 7 LastSaleDate ftDate 0 Index Name Fields In Index Options ---------------------------------------------- (none) CustomerID ixPrimary begin with MyTable do begin DatabaseName:='c:\temp'; TableName:='customer'; { Always make sure the table is closed first } Active:=False; { Update the field definitions using the existing field definitions from the table } FieldDefs.Update; { Same for the index definitions } IndexDefs.Update; { Now insert the new field definition. Notice the index position of 6 which is 0-based and the field number of 8 which is 1-based and equal to the next available field number since there are currently 7 field definitions for this table } FieldDefs.Insert(6,8,'LastSaleAmount',ftBCD,2,False); IndexDefs.Add('LastSaleAmount','LastSaleAmount',[]); { Now alter the table's structure } AlterTable; end; end; Customer Table Structure After Alteration Field # Name DataType Size ---------------------------------------------- 1 CustomerID ftString 10 2 CustomerName ftString 30 3 ContactName ftString 30 4 Phone ftString 10 5 Fax ftString 10 6 EMail ftString 30 7 LastSaleAmount ftBCD 2 8 LastSaleDate ftDate 0 Index Name Fields In Index Options ---------------------------------------------- (none) CustomerID ixPrimary LastSaleDate LastSaleDate (none) If you just want to add, instead of insert, a field definition, then just use the Add method instead of the Insert method, and leave off the index position parameter. Tim Young Elevate Software www.elevatesoft.com |
Mon, Oct 19 2015 11:04 PM | Permanent Link |
Adam H. | Hi Max,
> Does anyone know how to add a column to a DBISAM table using program code? Personally, I like to add my tables in my project using SQL. This way I can test outside as well using DBSYS to make sure all is OK. ie: procedure TForm1.addfield; begin MySQL.SQL.text = 'Alter Table MyTable Add "MyNewField" Varchar(10)'; MySQL.execsql; end; You can insert / redefine indexes as well using this. Just another option... Cheers Adam. |
Tue, Oct 20 2015 3:56 AM | Permanent Link |
Matthew Jones | Max Stewart wrote:
> Does anyone know how to add a column to a DBISAM table using program > code? If you want the DBISAM versions of my EDB file, let me know. I don't have them in a separate file at the moment as I just copy the unit and customise, but it wouldn't be hard to dig up (and I should probably do it anyway). -- Matthew Jones |
This web page was last updated on Thursday, April 18, 2024 at 10:42 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |