Forum Discussion
DDL Syntax
I am attempting to use the following DDL statement from within Access:
ALTER TABLE MyTableName ADD CONSTRAINT NOT NULL ( MyFieldName1, MyFieldName2 )
and I get a syntax error. Can someone please tell me what the issue is?
Also, I want to do something like the following
ALTER TABLE MyTableName ADD CONSTRAINT Check ( ( MyfieldName > 0 ) AND ( MyFieldName < 3500 ) )
But this doesn't work either.
I am doing this from the Query functionality within Access. I have another DDL statement that worked fine:
ALTER TABLE MyTableName ADD CONSTRAINT NoDupes UNIQUE ( MyFieldName1, MyFieldName2, MyFieldName3 )
Any/All help would be appreciated.
4 Replies
Hi,
> ALTER TABLE MyTableName ADD CONSTRAINT Check ( ( MyfieldName > 0 ) AND ( MyFieldName < 3500 ) )
1. You have to specify a name for the constraint.
2. You have to use ADO to add a Check constraint.
The VBA code could look like this:
CurrentProject.Connection.Execute "ALTER TABLE MyTableName ADD CONSTRAINT myConstraintName Check ( ( MyfieldName > 0 ) AND ( MyfieldName < 3500 ) )"
Servus
Karl
****************
Access News, Forever, DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg- YLMike92887Copper ContributorHi Karl --
Thanks for your reply.
I had a name for my constraint. I was sloppy about not including it. Sorry about that.
Thanks for your input on this type of constraint requiring the use of ADO. Is there a reference somewhere about what things require ADO? It would be nice to know this kind of thing.
Thanks again!
MikeHi,
I gave two conference presentations on this >20 years ago when JET4 (that brought the ADO pecularities) was still “fresh” and even then there wasn't much documentation on it. That has not improved. The only documentation to my knowledge still consists of these 3 texts:
Fundamental Microsoft Jet SQL for Access 2000
Intermediate Microsoft Jet SQL for Access 2000
Advanced Microsoft Jet SQL for Access 2000
In these texts, you then have to find out what only works via ADO and with which syntax.
Servus
Karl
****************
Access News, Forever, DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg
- George_HepworthSilver Contributor
Please show us the exact wording of the error messages.