Cita:
Iniciado por Libras SELECT @PrimaryKeyName =
COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE a
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS b
ON a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
WHERE a.table_name = @Tabla and constraint_type = 'Primary key'
Prueba con eso :)
Saludos!
Me refería a esta linea
SELECT @ID = MAX(@PrimaryKeyName) FROM @Tabla