Domanda

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

È stato utile?

Soluzione

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'

Altri suggerimenti

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)

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top