SQL Queries to Export Database Schema for SQL Server, MySQL, PostgreSQL, and Oracle

Exporting database schema is depends on the database type you are using. The queries export the following information (sample output is shown below):

SchemaTableColumnTypeLengthNullableDefault
publicUseridtextNullNoNull

The following queries show how to export database schema for the most popular databases (if you spot any mistake in the queries, please let us know):

SQL Server

            
SELECT TABLE_SCHEMA AS [Schema], TABLE_NAME AS [Table], COLUMN_NAME AS [Column], DATA_TYPE AS [Type] FROM INFORMATION_SCHEMA.COLUMNS -- AND TABLE_CATALOG='YOUR_TABLE_CATALOG' (if you are using table catalog) WHERE TABLE_SCHEMA = 'YOUR_DATABASE_NAME'

MySQL

            
SELECT TABLE_SCHEMA AS 'Schema', TABLE_NAME AS 'Table', COLUMN_NAME AS 'Column', DATA_TYPE AS 'Type' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "YOUR_DATABASE_NAME"

PostgreSQL

            
SELECT TABLE_SCHEMA AS "Schema", TABLE_NAME AS "Table", COLUMN_NAME AS "Column", DATA_TYPE AS "Type" FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'public' -- OR TABLE_SCHEMA = 'YOUR_DATABASE_NAME' (depending on setup)

Oracle

            
SELECT TABLE_SCHEMA AS 'Schema', TABLE_NAME AS 'Table', COLUMN_NAME AS 'Column', DATA_TYPE AS 'Type' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "YOUR_DATABASE_NAME"

Importing it into AI Bot

After exporting your database schema, export it as a CSV file and you can import it into AI Bot (Click the Settings button). After importing it, you can use it as autosuggestion for your AI Bot by typing / (slash) in the query editor.

References