The methods to generate the terahertz wave by optical rectification, photoconductive antennas, air plasmas and parametric generators are described in detail, then how to detect the terahertz wave by electro-optic sampling, photoconductive antennas and air plasmas are introduced as well. The terahertz time-domain spectroscopy and the asynchronous electro-optic sampling technique are also described. Furthermore, the applications of the terahertz technology to research fields, especially to the detection and identification of drugs are discussed. A terahertz spectrum database includes 38 kinds of drugs with a purity more than 99% is established. Moreover, the Artificial Neural Network(ANN) and a support vector machine are used to identify drugs automatically and the experimental methods and related theory are proposed to determine the purity and effective ingredients of drugs. By using a Gaussian software, individual species of drugs such as methyl-phenyl ammonia(MA), ketamine and heroin are conducted by spectral analysis, which provides a basis for implementing the drug inspection in laboratories. Finally, this paper reviews the developments of the terahertz technology briefly.