How do you assess programming related topics and avoid student cheating?
In general, it sounds like your problem is not to find out how to assess whether plagiarism occurred, but rather how to make tests that are harder to plagiarize. I will try to answer to both:

Plagiarism reduction can be achieved  building a database of questions to be leveraged to create "individualised" tests. To elaborate further, you could:


build a database with a number of questions larger than the one you intend to submit to students (as suggested in a previous answer)
build personalised tests by pulling questions randomly from the database above. 
randomise the input values of the questions (making up a trivial SQL example: "what is the n_th most likely value in m_th column of table k?" where n,m and k are randomly exctracted). 


Existing e-learning platforms (Moodle for example) contain all three features abobe, and allow you to collect the student responses in a centralised manner -
 so you don't need to reinvent the wheel.

Plagiarism detection becomes easier if you receive the test answers digitally. For humanities, text analytics would be needed, and I would recommend using off-the-shelf tools. For quantitative subjects, you can cluster students according to the submission time and score received in each test, and see whether some groups of students cluster too closely together (in small classes, no actual clustering algorithm is needed). This will not suffice to trigger punishment, but you can use it to focus on scrutinizing the student's thought process that led to the solution in a face-to-face exam.