SQL SERVER reads all table names in the database

       Sharing a little trick, we sometimes need to read the names of all data tables when operating the database, whether it is statistics or dynamic statement splicing operations, we can use the following statement to read all table names:

SELECT name
FROM sysobjects
WHERE xtype = 'u';

       result:


      In addition to the above statement, we can also use sp_MSforeachtable to implement the read statement as follows:

EXEC sp_MSforeachtable @command1="print '?'"
       However, using sp_MSforeachtable is a multiple loop query, and the result style is different from the above. We can choose according to our needs, and sp_MSforeachtable has many other uses, which we will introduce later.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325808364&siteId=291194637