I have started to read the book by Cecelia L. Allison and Neal A Berkowitz on SQL for Microsoft Access. and there is a syntex listed below that has been giving me a problem. I get an error with the word UNIQUE. So I removed it from the statement and then I get an error with the ON section at the end of the statements. Why is that. I am using MS Access 2000.
CREATE TABLE Manufacturers ( ManufacturersID INTEGER CONSTRAINT ManfID PRIMARY KEY, ToyID INTEGER NOT NULL, CompanyName CHAR (50) NOT NULL, Address CHAR (50) NOT NULL, City CHAR (20) NOT NULL, State CHAR (2) NOT NULL, Postalcode CHAR (5) NOT NULL, Areacode CHAR (3) NOT NULL, Phonenumber CHAR (8) NOT NULL, CONSTRAINT ToyFk FOREIGN KEY (ToyID) REFERENCES Toys (ToyID) ON UPDATE CASCADE ON DELETE CASCADE );
Software/Hardware used:
MS 2000
ASKED:
February 2, 2010 1:56 PM
UPDATED:
February 3, 2010 5:33 PM
This should work:
CREATE TABLE Manufacturers ( ManufacturersID INTEGER CONSTRAINT ManfID PRIMARY KEY, ToyID INTEGER NOT NULL, CompanyName CHAR (50) NOT NULL, Address CHAR (50) NOT NULL, City CHAR (20) NOT NULL, State CHAR (2) NOT NULL, Postalcode CHAR (5) NOT NULL, Areacode CHAR (3) NOT NULL, Phonenumber CHAR (8) NOT NULL, CONSTRAINT ToyFk FOREIGN KEY (ToyID) REFERENCES Toys);
1. ON DELETE/UPDATE is not supported by dialect (only via GUI).
2. Primary Key in REFERENCES Toys need not be listed
Yes. Thanks.
I think I should have clarified my answer a little.
1) The CREATE TABLE statement would work from the SQL View user interface if the ON UPDATE/DELETE CASCADE part is not present in the CONSTRAINT clause (but you won’t have cascading updates/deletes). If you need that functionality you would have to execute the CREATE TABLE statement or an additional ALTER TABLE statement (to add the constraint) through ADO.
2) Primary key fields don’t need to be specified for the referenced table, but won’t cause any errors if they are.
in the statement of the phonenumber I would like to make this a unquie statement. How would this be accomplished?
And what do you mean by (1) below ON DELETED/UPDATE is not supported by dialect (only via GUI)?
So why would the author of the book have created the syntex the way it is if it would not work with Access?
Hmmm. I don’t know
It works with Access, but not from the user interface (I might be some way to make it work, but I’m not an Access expert).
I found this on MSDN (Intermediate Microsoft Jet SQL for Access 2000)
“SQL Enhancements
In Access 2000, many enhancements were made to the SQL implementation in the Microsoft Jet 4.0 data engine in order to support new features of Access, to conform more closely to the ANSI-92 standard, and to allow for greater compatibility between Access and Microsoft® SQL Server™. The Jet database engine now has two modes of SQL syntax: one that supports previously used SQL syntax, and one that supports the new SQL syntax. It is very important to note that some of the new SQL syntax is available in code only when you use ActiveX® Data Objects (ADO) and the Jet OLE DB provider, and is not currently available through the Access SQL View user interface or DAO. This article points out when a certain SQL command is available only through the Jet OLE DB provider and ADO.”
To create the unique constraint:
1)
or
2)
or using an ALTER TABLE statement.
: So why would the author of the book have created the syntex the way it is if it would not work with Access?
Maybe this example will work via ADO in a module. But will not in SQL query console.