Database issue for everyone (QUERY)

68 views Asked by At

I want to create a query that generates the table name. I tried something like this :

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE  TABLE_SCHEMA='mytableName'

but it return an empty query. So , any ideas ? Thx

3

There are 3 answers

0
CloudyMarble On BEST ANSWER

Why WHERE AND TABLE_SCHEMA='mytableName' The AND is invalid at this point.

Besides the Tablename is in the column TABLE_NAME not TABLE_SCHEMA, maby you should try to filter using the schema name instead of the table name like:

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='YOUR_SCHEMA_NAME'

Or if you need information regarding a specific table:

SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME='YOUR_TABLE_NAME'
1
Valin On

There is incorrect syntax at "WHERE AND".

You should execute:

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='mytableName'

You should try TABLE_SCHEMA='dbo', it looks like your schema 'mytableName' is really empty.

0
Peter van der Wal On

To start with: that query is invalid (remove the AND).

2nd it's empty because there are no tables within the schema (also called database) named mytableName.

Also take a look at SHOW TABLES (documentation) and SHOW DATABASES (documentation)