Re: Coding at table with multiple primary key columns

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: ryan (ryan_at_discussions.microsoft.com)
Date: 02/15/05


Date: Tue, 15 Feb 2005 13:41:15 -0800

Hey Andi, this solution does not work I am getting a Constraint error. I am
using System.Data.OleDb. I dont know if that makes a difference. Also, will
the unique contraint do the same thing as the primary key. I dont think so.
All I need the key for is editing the table b/c if I dont have one and I try
to update the table I will get an error. Thanks

"Andi Mayer" wrote:

> On Tue, 15 Feb 2005 10:49:11 -0800, "ryan"
> <ryan@discussions.microsoft.com> wrote:
>
> >I am trying to create a talbe by coding in VB.Net and I know how to create a
> >table with one column as a primary key, but I need mulitple columns as the
> >key how can I do that? Right now I use:
> >SQL = "CREATE TABLE " & type & "_games_today ([Away] TEXT(20) CONSTRAINT
> >K_Away KEY, [Home] TEXT(20), [Away_Score] INTEGER, [Home_Score] INTEGER,
> >[Spread] SINGLE, [Home_Fav] BIT, [OverUnder] SINGLE, [Date] TEXT(20) , [Day]
> >TEXT(10), [Game] INTEGER)".
> >To make one column the PK, but if I add a second or thrid constraint as as
> >PK in the same way it does not work. Can someone help me?
>
> out of the help file: Topic Microsoft Jet SQL reference
>
> This example creates a new table called MyTable with two text fields,
> a Date/Time field, and a unique index made up of all three fields.
>
> Sub CreateTableX2()
> Dim dbs As Database
> ' Modify this line to include the path to Northwind
> ' on your computer.
> Set dbs = OpenDatabase("Northwind.mdb")
> ' Create a table with three fields and a unique
> ' index made up of all three fields.
>
> dbs.Execute "CREATE TABLE MyTable " _
> & "(FirstName CHAR, LastName CHAR, " _
> & "DateOfBirth DATETIME, " _
> & "CONSTRAINT MyTableConstraint UNIQUE " _
> & "(FirstName, LastName, DateOfBirth));"
> dbs.Close
>
> End Sub
>
> ---
> If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
> MW
>



Relevant Pages

  • RE: creating a new database
    ... if i dont link them to the courses and costs, how would we need what have ... ---CourseID Autonumber Primary Key ...
    (microsoft.public.access.modulesdaovba)
  • RE: CANT see EDIT UPDATE CANCEL Buttons for DATAGRID
    ... For updating the SQL database using data grid, is primary key required? ... dont have a primary key in the SQl table. ... >> records are displayed where company name matches with user input. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Access 2K3, SQL Server 2K5, "Instead of" Trigger Problem
    ... why dont you just use a simple integer as a PK ... and then you can take your extra special PK and shove it wherever you ... Sylvain Lafontaine ... the primary key of the primary table if the new row has a null value ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Clustered columns confusion
    ... "Chinmay" wrote in message ... > Yes and i dont have a Primary Key on Image column. ...
    (microsoft.public.sqlserver.server)