We present a homogeneous analysis of 1023 DBZ/DZ(A) and 319 DQ white dwarf stars taken from the Montreal White Dwarf Database. This represents a significant increase over the previous comprehensive studies on these types of objects. We use new trigonometric parallax measurements from the Gaia second data release, together with photometry from the Sloan Digital Sky Survey, Pan-STARRS, Gaia, or BVRI from the literature, which allow the determination of the mass for the majority of the objects in our sample. We use the photometric and spectroscopic techniques with the most recent model atmospheres available, which include high-density effects, to accurately determine the effective temperature, surface gravity, and heavy element abundances for each object. We study the abundance of hydrogen in DBZ/DZ white dwarfs and the properties of the accreted planetesimals. We explore the nature of the second sequence of DQ stars using proper motions from Gaia, and highlight evidence of crystallization in massive DQ stars. We also present mass distributions for both spectral types. Finally, we discuss the implications of our findings in the context of the spectral evolution of white dwarfs, and provide the atmospheric parameters for each star.