Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / August 2005

Tip: Looking for answers? Try searching our database.

Create Table with a multiple column primary key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerry G. - 30 Aug 2005 18:29 GMT
I am trying to create a table with a multiple column primary key. When I run
the code below I receive the follwoing error message:

"Cannot add multiple PRIMARY KEY constraints to table 'Daily_Price_ImportT'"

What is the correct coding to create a table with a multiple column primary
key?

Thanks,

Gerry

Sub CreateImportTable(cnxn As ADODB.Connection)

 Dim TableStr As String

On Error GoTo Import_Daily_Price_Err

'Create Import tables

  TableStr = "IF NOT EXISTS(SELECT TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES " & _
             "WHERE TABLE_NAME = 'Daily_Price_ImportT') " & _
             "Create Table Daily_Price_ImportT " & "( " & _
             "TerminalNo Int NOT NULL PRIMARY KEY, " & _
             "Supplier nvarchar(100) NOT NULL PRIMARY KEY, " & _
             "Terminal_Name nvarchar(50) NOT NULL PRIMARY KEY, " & _
             "Terminal_Abbr nvarchar(20) Null, " & _
             "Terminal_City nvarchar(50) Null, " & _
             "Terminal_State nvarchar(5) Null, " & _
             "Product_Name nvarchar(120) Null, " & _
             "Brand_Type nvarchar(5) Null, " & _
             "Effective_Date datetime Null, " & _
             "Effective_Time datetime Null, " & _
             "Price real Null, " & _
             "Change real Null, " & _
              ")"
             
  cnxn.Execute TableStr
Gerry G. - 30 Aug 2005 21:29 GMT
thank you for reviewing my post. I received the solution on another forum see
below:

TableStr = "IF NOT EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES "
& _
          "WHERE TABLE_NAME = 'Daily_Price_ImportT') " & _
          "Create Table Daily_Price_ImportT ( " & _
          "TerminalNo Int NOT NULL, " & _
          "Supplier nvarchar(100) NOT NULL, " & _
          "Terminal_Name nvarchar(50) NOT NULL, " & _
          "Terminal_Abbr nvarchar(20) Null, " & _
          "Terminal_City nvarchar(50) Null, " & _
          "Terminal_State nvarchar(5) Null, " & _
          "Product_Name nvarchar(120) Null, " & _
          "Brand_Type nvarchar(5) Null, " & _
          "Effective_Date datetime Null, " & _
          "Effective_Time datetime Null, " & _
          "Price real Null, " & _
          "Change real Null, " & _
          "CONSTRAINT myPrimaryKey PRIMARY KEY (TerminalNo, Supplier,
Terminal_Name)" & _
          ")"

> I am trying to create a table with a multiple column primary key. When I run
> the code below I receive the follwoing error message:
[quoted text clipped - 35 lines]
>                
>    cnxn.Execute TableStr
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.