Can anybody help me understand why I get the error
"Syntax error in CONSTRAINT clause"?
I get it in Access 2003 and Access 2007.
Both are clean installs with no add-ins
Running this code in VBA, or pasting the SQL directly in a query results in the same error.
Sub test()
sTableName = "Test"
sSQL = "CREATE TABLE " & sTableName & "_Config (" _
& "[idConfig] Int Primary Key," _
& "[Config] Memo," _
& "[Instrument] int," _
& "[Serial_No] Text(25)," _
& "[Firmware] int," _
& "[Orientation] int," _
& "[Sensors] int," _
& "[Sensor_Size] float," _
& "[Sensor_1_Distan ce] float)"
DoCmd.RunSQL sSQL
sSQL = "CREATE TABLE " & sTableName & "_Leader (" _
& "[idLeader] Int Primary Key," _
& "[idGroup] int," _
& "[idFile] int," _
& "[idConfig] int," _
& "[DateTime] DateTime," _
& "[Heading] float, [Pitch] float, [Roll] float," _
& "[Pressure] float, [Depth_BSL] float, [Height_ASB] float,"
_
& "[Min_Valid_Senso r] int, [Max_Valid_Senso r] int," _
& "[ASM_Bed_Level] float," _
& "CONSTRAINT [FK_Test_Leader_ idConfig] FOREIGN KEY ([idConfig]) REFERENCES [Test_Config] ([idConfig]) ON DELETE CASCADE ON UPDATE CASCADE" _
& ")"
DoCmd.RunSQL sSQL
End Sub
The first table is created just fine.
And if I leave the constraint clause out, the second table is created also.
If I try to run it as an SQL query right in Access, after the error is delivered, it highlights the word DELETE, and if I reverse the update and delete portions, it highlights the word UPDATE.
I have looked up the clause in Access help and even using their example, i get the same error.
Any help will surely be appreciated!
3 5209 FishVal 2,653
Recognized Expert Specialist
Hi, bilbo.
It seems that constraints (at least DRI) are not supported via DAO interface. But via ADO it runs flawlessly. -
Public Sub CreateTableWithDRIConstraint()
-
-
'ADO connection performs operation flawlessly
-
CurrentProject.Connection.Execute _
-
"CREATE TABLE tblChild (keyID Long, CONSTRAINT FK_keyID FOREIGN KEY (keyID)" & _
-
" REFERENCES tbl(keyID) ON DELETE CASCADE);"
-
'DAO connection throws an error
-
CurrentDb.Connection.Execute _
-
"CREATE TABLE tblChild (keyID Long, CONSTRAINT FK_keyID FOREIGN KEY (keyID)" & _
-
" REFERENCES tbl(keyID) ON DELETE CASCADE);"
-
-
End Sub
-
Regards,
Fish
Thanks!!!
I'll add this to the long and growing list of things I tried to over complicate!
I was able to adapt my code using your tip and it works just great!
Thanks loads!
FishVal 2,653
Recognized Expert Specialist
You are quite welcome.
Best regards,
Fish
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a particular surname in a
particular town.
I can select the records fine with this syntax (testing in Oracle SQL* Plus)
SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME,
NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
|
by: Brian Basquille |
last post by:
Just started learning SQL recently.
But one thing i'm still not clear on is about altering relationships between
tables after they've been created.
Instead of creating a foreign key when the table is first created - i create
the table and then run a query to set the foreign key and relationship
(one-to-one, one-to-many etc)
Anyways, long story short is i want to create a one-to-one relationship with
|
by: Jan van Veldhuizen |
last post by:
The UPDATE table FROM syntax is not supported by Oracle.
I am looking for a syntax that is understood by both Oracle and SqlServer.
Example:
Table1:
id name city city_id
1 john newyork null
|
by: tom |
last post by:
I am new to SQL administration.
>From a list of IDs that are the primary key in one table (i.e. Customer
Table), I want to make changes in tables that use those IDs as a
foreign key.
Basically I want to say:
If fk_ID is in list then
do these statements to that record
|
by: Robert Stearns |
last post by:
I don't understand the reference "2" in the following message. There is
only a primary key constraint on the named table. It is generated by
default and Im not inserting a value for it.
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or foreign key update caused by a DELETE statement are not valid because
the primary key, unique constraint or unique index identified by "2"
constrains table "IS3.ENTITIES_PUB" from...
| |
by: Alicia |
last post by:
Does anyone know why I am getting a "Syntax error in Create Table
statement". I am using Microsoft Access SQL View to enter it. Any
other problems I may run into?
CREATE TABLE weeks
(
weekstart datetime not null primary key,
weekend datetime not null
)
|
by: Jerry |
last post by:
Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm not completely
clear on the fundamentals here. I update the table in my
dataset, then I update the table on the server through the
dataAdapter. I think I have a handle on the...
|
by: HH |
last post by:
I try to make a script for generating backend databases. When I try to
make a relationship between a table named 'users' and another table
name 'layouts' an error occurs.
Option 1:
CurrentDB.Execute "ALTER TABLE layouts ADD CONSTRAINT users_layouts
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE"
Option 2:
DoCmd.RunSQL "ALTER TABLE layouts ADD CONSTRAINT users_layouts FOREIGN
|
by: Jeff Kish |
last post by:
Hi.
I have a procedure with this in it (there are no other references to
asset_number_bak_tmp_pk in the procedure and it calls nothing else written by
me, just system calls or normal dml).
create table #asset_bak(
asset_number varchar(60) not null,
asset_desc varchar(100) null,
location varchar(40) null,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |