Murray Brown
asked on
VB.net remove all primary keys from SQL Table
Hi
What VB.net code would I use to remove all the primary keys from a SQL table?
Thanks
What VB.net code would I use to remove all the primary keys from a SQL table?
Thanks
A given table could have only one primary key, so you don't need to worry about any kind of looping or multiple entries.
hmm, need new glasses. I really read tables..(
ASKER
I use the following code to add the keys. What similar code would I use to remove them
Dim oSQL As String
oSQL = "ALTER TABLE " & oTable
oSQL = oSQL & " ADD CONSTRAINT pk_" & oTable & " PRIMARY KEY ([" & oColumn1 & "], [" & oColumn2 & "])"
'oSQL = oSQL & " GO"
Dim cn As New SqlConnection(Globals.This AddIn.oRIG HT.lblConn ectionStri ng.Text)
Dim cmd As New SqlCommand(oSQL, cn)
cn.Open()
cmd.ExecuteNonQuery()
Dim oSQL As String
oSQL = "ALTER TABLE " & oTable
oSQL = oSQL & " ADD CONSTRAINT pk_" & oTable & " PRIMARY KEY ([" & oColumn1 & "], [" & oColumn2 & "])"
'oSQL = oSQL & " GO"
Dim cn As New SqlConnection(Globals.This
Dim cmd As New SqlCommand(oSQL, cn)
cn.Open()
cmd.ExecuteNonQuery()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Something like
Open in new window
.