Monday, 3 May 2021

Get Table & Schema details using SQL Query

This first query will return all of the tables in the database you are querying.

 SELECT

  *

 FROM

 INFORMATION_SCHEMA.TABLES

 where table_name like '%tablename%'


The second query will return a list of all the columns and tables in the database you are querying.

SELECT
  	TABLE_NAME,
COLUMN_NAME
FROM
  	INFORMATION_SCHEMA.COLUMNS

Or, you can also query for just the COLUMNS from a specific table and return the column names from the specific table ‘Album’ in our database.

SELECT
	COLUMN_NAME
FROM
  	INFORMATION_SCHEMA.COLUMNS
WHERE
	TABLE_NAME = 'Album'

No comments:

Post a Comment