schema
necesito saber como sacar cual de los campos es primary key.. este es el codigo de mi metodo.. se como sacar el nombre , tipo de datos.. pero no como sacar la clave primarya ni cuando es auto_increment..
esto es en sql server y asp..
agradezco si alguien me puede ayudar
<%@ Language = VBSCRIPT %>
<% Option Explicit %>
<%
Const adSchemaTables = 20
Const adSchemaColumns = 4
'Column variables
Dim iLength, iPrecision, iScale, iDefaultValue
Dim tabla, sentencia, tabla2
Dim objConn, objTableRS, objColumnRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "driver=SQL Server;server=localhost;database=scher_uruguay;uid=Uruguay;pwd=01ffuyshr;APP=ASP Script"
'objConn.ConnectionString = "driver={MySQL ODBC 3.51 Driver};server=localhost;database=scher_uruguay;uid=Uruguay;pwd=01ffuyshr;APP=ASP Script"
objConn.Open
Set objTableRS = objConn.OpenSchema(adSchemaTables, _
Array(Empty, Empty, Empty, "TABLE"))
Do While Not objTableRS.EOF
tabla="CREATE TABLE "
tabla=tabla & objTableRS("Table_Name").Value & " ("
tabla2="CREATE TABLE "& objTableRS("Table_Name").Value & " ("
Set objColumnRS = objConn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, objTableRS("Table_Name").Value))
Do While Not objColumnRS.EOF
iLength = objColumnRS("Character_Maximum_Length")
iPrecision = objColumnRS("Numeric_Precision")
iScale = objColumnRS("Numeric_Scale")
iDefaultValue = objColumnRS("Column_Default")
if tabla<> tabla2 then
tabla=tabla & ","
end if
tabla=tabla & objColumnRS("Column_Name")&" "
if objColumnRS("Data_Type")=2 then
tabla=tabla & "Integer "
elseif objColumnRS("Data_Type")=3 then
tabla=tabla & "Long Integer "
elseif objColumnRS("Data_Type")=17 then
tabla=tabla & "Unsigned Byte "
elseif objColumnRS("Data_Type")=129 then
tabla=tabla & "VarChar"
If iLength <> ""then
tabla=tabla & "("& iLength &")"
end if
elseif objColumnRS("Data_Type")=130 then
tabla=tabla & "TEXT"
elseif objColumnRS("Data_Type")=131 then
tabla=tabla & "131"
elseif objColumnRS("Data_Type")=135 then
tabla=tabla & "Time Stamp "
else
tabla=tabla & objColumnRS("Data_Type")
end if
If objColumnRS("Is_Nullable") then
else
tabla=tabla & " NOT NULL"
End If
if iDefaultValue <> "" then
tabla=tabla & "default " & iDefaultValue
end if
objColumnRS.MoveNext
Loop
'if iDefaultValue <> "" then
tabla=tabla & ", PRIMARY KEY (id)"
'end if
objTableRS.MoveNext
Set objColumnRS = Nothing
tabla=tabla & ")"
sentencia= sentencia & tabla & (chr(13))
tabla = ""
Loop
response.write sentencia
objTableRS.Close
Set objTableRS = Nothing
objConn.Close
Set objConn = Nothing
%>
esto es en sql server y asp..
agradezco si alguien me puede ayudar
<%@ Language = VBSCRIPT %>
<% Option Explicit %>
<%
Const adSchemaTables = 20
Const adSchemaColumns = 4
'Column variables
Dim iLength, iPrecision, iScale, iDefaultValue
Dim tabla, sentencia, tabla2
Dim objConn, objTableRS, objColumnRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "driver=SQL Server;server=localhost;database=scher_uruguay;uid=Uruguay;pwd=01ffuyshr;APP=ASP Script"
'objConn.ConnectionString = "driver={MySQL ODBC 3.51 Driver};server=localhost;database=scher_uruguay;uid=Uruguay;pwd=01ffuyshr;APP=ASP Script"
objConn.Open
Set objTableRS = objConn.OpenSchema(adSchemaTables, _
Array(Empty, Empty, Empty, "TABLE"))
Do While Not objTableRS.EOF
tabla="CREATE TABLE "
tabla=tabla & objTableRS("Table_Name").Value & " ("
tabla2="CREATE TABLE "& objTableRS("Table_Name").Value & " ("
Set objColumnRS = objConn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, objTableRS("Table_Name").Value))
Do While Not objColumnRS.EOF
iLength = objColumnRS("Character_Maximum_Length")
iPrecision = objColumnRS("Numeric_Precision")
iScale = objColumnRS("Numeric_Scale")
iDefaultValue = objColumnRS("Column_Default")
if tabla<> tabla2 then
tabla=tabla & ","
end if
tabla=tabla & objColumnRS("Column_Name")&" "
if objColumnRS("Data_Type")=2 then
tabla=tabla & "Integer "
elseif objColumnRS("Data_Type")=3 then
tabla=tabla & "Long Integer "
elseif objColumnRS("Data_Type")=17 then
tabla=tabla & "Unsigned Byte "
elseif objColumnRS("Data_Type")=129 then
tabla=tabla & "VarChar"
If iLength <> ""then
tabla=tabla & "("& iLength &")"
end if
elseif objColumnRS("Data_Type")=130 then
tabla=tabla & "TEXT"
elseif objColumnRS("Data_Type")=131 then
tabla=tabla & "131"
elseif objColumnRS("Data_Type")=135 then
tabla=tabla & "Time Stamp "
else
tabla=tabla & objColumnRS("Data_Type")
end if
If objColumnRS("Is_Nullable") then
else
tabla=tabla & " NOT NULL"
End If
if iDefaultValue <> "" then
tabla=tabla & "default " & iDefaultValue
end if
objColumnRS.MoveNext
Loop
'if iDefaultValue <> "" then
tabla=tabla & ", PRIMARY KEY (id)"
'end if
objTableRS.MoveNext
Set objColumnRS = Nothing
tabla=tabla & ")"
sentencia= sentencia & tabla & (chr(13))
tabla = ""
Loop
response.write sentencia
objTableRS.Close
Set objTableRS = Nothing
objConn.Close
Set objConn = Nothing
%>
