I have a mxd file with some query layers (File->Add Data->Add Query Layers). Is it possible to change the query layers's definition with arcpy? I need change both the SQL statement and the database connection.
Do you mean the Query Layer's Definition Query? I think you can although I never tried it. You should use ListTableViews function in arcpy.mapping module