iman_a_r
asked on
Create a Microsoft Access (.mdb) and tables
Hi all.
I am using Delphi 6.
How can i create Microsoft Access (.mdb) database in my delphi application.
And how can i make tables in a (.mdb) database.
I see some component in SERVER tab in delphi.
I am using Delphi 6.
How can i create Microsoft Access (.mdb) database in my delphi application.
And how can i make tables in a (.mdb) database.
I see some component in SERVER tab in delphi.
geo, you become faster :-))
I'm currently writing few things using access and that code above (similar) is opened in my Delphi window right now :-)
ASKER
geobul,
how can i determine fields property of table in this maner.
It is very important for me.
how can i determine fields property of table in this maner.
It is very important for me.
Hi,
What property? Using CREATE TABLE statement you define:
- table name
- fields names
- fields types
- fields lengths (for string type fields)
You may also define:
- NOT NULL property
- PRIMARY KEY field/s
- multiply
Examples (All words in capital letters are reserved words. The other words are names of tables, fields and indexes):
// create Table1: NOT NULL example
CREATE TABLE Table1 (Field1 INTEGER NOT NULL, Field2 CHAR(20), Field3 DATETIME)
// create Table2: Primary Key example
CREATE TABLE Table2 (id INTEGER CONSTRAINT Table2id PRIMARY KEY, Name CHAR(50), DateOfBirth DATETIME)
// create Table3: complex unique index
// if you may also use PRIMARY KEY instead of UNIQUE for complex primary key
CREATE TABLE Table3 (FirstName CHAR(20), LastName CHAR(20), DateOfBirth DATETIME, CONSTRAINT Table3Constraint UNIQUE (FirstName, LastName, DateOfBirth))
Regards, Geo
What property? Using CREATE TABLE statement you define:
- table name
- fields names
- fields types
- fields lengths (for string type fields)
You may also define:
- NOT NULL property
- PRIMARY KEY field/s
- multiply
Examples (All words in capital letters are reserved words. The other words are names of tables, fields and indexes):
// create Table1: NOT NULL example
CREATE TABLE Table1 (Field1 INTEGER NOT NULL, Field2 CHAR(20), Field3 DATETIME)
// create Table2: Primary Key example
CREATE TABLE Table2 (id INTEGER CONSTRAINT Table2id PRIMARY KEY, Name CHAR(50), DateOfBirth DATETIME)
// create Table3: complex unique index
// if you may also use PRIMARY KEY instead of UNIQUE for complex primary key
CREATE TABLE Table3 (FirstName CHAR(20), LastName CHAR(20), DateOfBirth DATETIME, CONSTRAINT Table3Constraint UNIQUE (FirstName, LastName, DateOfBirth))
Regards, Geo
- multiply
should be:
- multiple-field index
should be:
- multiple-field index
ASKER
GeoBul,
I need determine property "Allow zero length" of Field
I need determine property "Allow zero length" of Field
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Geobul.
I test what you say, but NOU NULL define propert "Requier" not "Allow Zero Length"
I think this way of creating is not so good.
Do you know better way(for example with delphi components in server tab in delphi 6)
I test what you say, but NOU NULL define propert "Requier" not "Allow Zero Length"
I think this way of creating is not so good.
Do you know better way(for example with delphi components in server tab in delphi 6)
My mistake, sorry. You are right. I can't find a way to set that property using SQL :-(
I have no experience using these components.
I have no experience using these components.
1. Creating an mdb file:
uses ComObj;
// Version 3=95, 4=97, 5=2000
procedure CreateAccessDatabase(MDBNa
var
Catalog: Variant;
begin
Catalog := CreateOleObject('ADOX.Cata
Catalog.Create('Provider=M
end;
// usage
procedure TForm1.Button1Click(Sender
begin
CreateAccessDatabase('D:\n
end;
2. Creating tables:
Use (ADO)Query component with 'CREATE TABLE' sql statement and use ExecSQL instead of Open.
Example:
procedure TForm1.Button2Click(Sender
begin
with ADOQuery1 do begin
Close;
ConnectionString := 'Provider=Microsoft.Jet.OL
SQL.Clear;
SQL.Add('CREATE TABLE Table1 (Field1 char(20), Field2 integer)');
ExecSQL;
end;
end;
Regards, Geo