The fundamental lemma due to Willems et al. "A note on persistency of excitation," Syst. Control Lett., vol. 54, no. 4, pp. 325-329, 2005 plays an important role in system identification and data-driven control. One of the assumptions for the fundamental lemma is that the underlying linear timeinvariant system is controllable. In this paper, the fundamental lemma is extended to address system identification for uncontrollable systems. Then, a data-driven algebraic test is derived to check whether the underlying system is controllable or not. An algorithm based on the singular value decomposition of a Hankel matrix constructed from the data is provided to implement the developed test. The algorithm has cubic computational cost. Examples are given to illustrate the theoretical results.