Finding the key fields in SQL database.

Nathan

Perch
I am using the following code to list the fields in a database table. What I need to do though is know which ones are the 'key' fields. Can anyone help?
Thanks very much. Nathan



set conntemp=server.createobject("adodb.connection")
conntemp.open strCon
set rsTable=conntemp.execute(SQLStr)

for each FieldName in rsTable.fields
response.write FieldName.Name
next

rsTable.close
set rsTable=nothing
conntemp.close
set conntemp=nothing
 
try this:

Code:
set rsprimarykey = conn.execute("select * from information_schema.table_constraints where (table_name = '" & db & "') AND (constraint_type = 'Primary Key')")
set rsprimarykey2 = conn.execute("select column_name from information_schema.key_column_usage where (constraint_name = '" & rsprimarykey("constraint_name") & "')")
primarykey = rsprimarykey2("column_name")



Nathan said:
I am using the following code to list the fields in a database table. What I need to do though is know which ones are the 'key' fields. Can anyone help?
Thanks very much. Nathan



set conntemp=server.createobject("adodb.connection")
conntemp.open strCon
set rsTable=conntemp.execute(SQLStr)

for each FieldName in rsTable.fields
response.write FieldName.Name
next

rsTable.close
set rsTable=nothing
conntemp.close
set conntemp=nothing
 
Hmmm...not that well up on Access/Jet. Maybe you could try a Google search "How to list Primary Key fields in Access" or something?
 
That's great - thanks "jonyah" It is exactly what we needed. With help from a mate Sofri, we now have the system working exactly as we wanted.

Again, thanks very much, pop down anytime to the taverna for a well deserved beer from me!

Nathan

www.agni.gr
 
np, just trying to give back what I can.



Nathan said:
That's great - thanks "jonyah" It is exactly what we needed. With help from a mate Sofri, we now have the system working exactly as we wanted.

Again, thanks very much, pop down anytime to the taverna for a well deserved beer from me!

Nathan

www.agni.gr
 
Back
Top