A D major scale employs F-sharp and C-sharp, while a G major scale employs F-sharp. The consistent employment of sharp(s) or flat(s) in the scale becomes a musical notation called key signature, designating notes that are to be played with sharps or flats throughout the piece unless altered by an accidental.
3. Circle of Fifths
A D major scale employs F-sharp and C-sharp in the key signature while a G major scale employs F-sharp only. Why is that? The circle of fifths is a geometrical representation of relationships covering all 12 pitches in music. You will see the operation starting from the apex and proceeding clockwise by ascending fifths, so a G major has one sharp, a D major has two sharps, and so on adding a sharp each time. Similarly, it proceeds counterclockwise from the apex by descending fifths, so an F major has one flat, a B-flat major has two flats, and so on. At the bottom of the circle, the sharp and flat keys overlap, showing enharmonic key signatures.