Link to home
Create AccountLog in
Avatar of nirdu
nirdu

asked on

How to add a filde to a Data Base table in run time ?

Hi

I need some help in Data Base programing.
How can I add a new filde, to an exists table, in run time ?

Thanks for your help.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

query.sql.text := 'alter table TABLENAME add (COLUMNNAME TYPE)'
query.execsql;

just from head -> means untested and typos possible

i recommend to refere your databasemanual about the correct syntax

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of _JHL_
_JHL_

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I know it is not database TA, but would like to say that
better use
sql = "ALTER TABLE table_name ADD field DOUBLE  NULL";
otherwaie You should also specify default value for a field (at least on some databases)

mokule
Avatar of _JHL_
_JHL_

It depend of the type of the field... you can set it as char, double, etc.. and in same cases the defaul value, also where iin the table (after any field)


JHL
hi dear friend ...
it is so easy. just download this complete Project. all that you want is here :
+) http://mizan3.com/delphi/databases-addfield.zip
Regards friend.
Avatar of nirdu

ASKER

Hi

Alter works the way I want, but it is very slow ....
Is there a way to rash it ?

thanks
Usually it´s the best form. But there are other functions that you can use, but depend of the component that you are useing to access the table. By ex. if you are using ADO TABLE, you can make modifications as Alter with adotable1.fields.add(Tfield).
But I think that the best and fastest way it´s by SQL( Alter)


Regards

JHL