Ms access 2003 ddl?
Hi. this is a question for experienced users of ms access.
i can do this easily in sql server, but i would like to know the sql (with a focus on the data definition langauge) to do the following in ms access:
1. retrieve all the table names in an access database.
2. retrieve all the views (queries) in an access database.
3. all the columns, for a given table, in an access database.
4. retrieve all the column properties, for a given table, in an access database.
5. script a table to give a create statement including data types and defaults.
6. create, alter and drop a table
i know you can get all this from access itself, but i have a need to do this programmatically.
thanks in advance.
Answer
'in vba
dim db as database
set db = currentdb
dim mytable as tabledef
'tables
for i=0 to db.tabledefs.count-1
set mytable=db.tabledefs(i)
debug.print mytable.name
'or just
debug.print db.tabledefs(i).name
next i
'queries (views)
dim myquery as querydef
'similar code as above
'fields (columns)
set tbl = db.tabledefs(tablename)
for i=0 to tbl.fields.count-1
'etc.
docmd.runsql "alter table [paxzone] drop column [fixfk]"
docmd.runsql "alter table [label] add column [escapement] single"
docmd.runsql "drop table [xyzzy]"
skipped some, but lotta typing here. tired. too much coffee cake @ xmas. sorry. anyway, if you have a database, any database open in access (or open access and create a new, empty db), press alt-f11 to get to vba. then press f2 to get the object model for access and dao. you can search for querydef and the like, get properties, collections. i reckon
there is
sample code there as well. peace.
Related Products
Warning: DOMDocument::loadXML() [
domdocument.loadxml]: Extra content at the end of the document in Entity, line: 2 in
/home/gmartin/public_html/ukmicrosoftquicktips/includes/domxml-php4-to-php5.php on line
61
Fatal error: Call to a member function document_element() on a non-object in
/home/gmartin/public_html/ukmicrosoftquicktips/includes/amazon.php on line
50