To construct the key signature of a major key, it is important to remember that C major has no key signature. Sharps or flats are used in all other scales.
Major keys based on a flat note, G flat, E flat, D flat, etc. use key signatures with flats. The only exception is F major. So if you are looking for a key signature, you can assume that it uses sharps if it is not F major or does not begin with a flat:
Once the accidentals used in the key signature are known, the following procedure can be used to create the key signature:
Follow the order of the sharps until you reach the one that is a half-step below the chosen major scale. For example, A major, F#, C#, G#. G# is a half-step below A. Therefore, sharps are F#, C#, G#.
Follow the order of the flats until you find the key you are looking for. Then add another one. For example, A flat major, B flat, E flat, A flat, D flat. D flat comes after A flat, so the flats are B flat, E flat, A flat and D flat.
This method does not apply to the major scale of F, which has a flat. Therefore this key signature must be memorised.
In the case of minor keys, the relative major must be identified. Relative scales have the same key signatures.
See S > Scales for related topics.