Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all data of all tables

I want to display all data in my Database without writing a select for each table - how can I do this?

I do not want to do this:

select * from Customer
select * from Employee
select .............

I am using TSQL with MSSQL Server.

like image 320
Salah Sanjabian Avatar asked Aug 18 '11 10:08

Salah Sanjabian


People also ask

How will you display data from multiple tables?

There are many ways to display data from more than one table. You can join tables or views by a common column. You can also merge data from two or more tables or views into a single column or create a subquery to retrieve data from several tables. You can use a SELECT statement to join columns in two or more tables.

How do you show all data in a database?

The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.


2 Answers

DECLARE @sqlText VARCHAR(MAX)
SET @sqlText = ''
SELECT @sqlText = @sqlText + ' SELECT * FROM ' + QUOTENAME(name) + CHAR(13) FROM sys.tables
EXEC(@sqlText)
like image 159
Vishal Gajjar Avatar answered Nov 06 '22 09:11

Vishal Gajjar


For mysql:

  1. Run SELECT information_schema.TABLES.TABLE_NAME FROM information_schema.TABLES where table_schema='db_name'

  2. Create a loop which will run select query for each table gotten from the first query.

like image 24
Andrej Ludinovskov Avatar answered Nov 06 '22 08:11

Andrej Ludinovskov