0% found this document useful (0 votes)
3 views

schemu_ff

The document outlines a database schema designed for managing user inputs and generating SQL queries based on natural language requests. It includes tables for Users, UserInputs, DatabaseSchema, TableColumns, Synonyms, Intents, QueryMappings, and GeneratedQueries, detailing their structures and relationships. The schema facilitates the mapping of user queries to SQL commands, enhancing query generation and interpretation through synonyms and intent classification.

Uploaded by

as8487
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

schemu_ff

The document outlines a database schema designed for managing user inputs and generating SQL queries based on natural language requests. It includes tables for Users, UserInputs, DatabaseSchema, TableColumns, Synonyms, Intents, QueryMappings, and GeneratedQueries, detailing their structures and relationships. The schema facilitates the mapping of user queries to SQL commands, enhancing query generation and interpretation through synonyms and intent classification.

Uploaded by

as8487
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

UserInputs

DatabaseSchema
Input_id
User_id Schema_id
Input_text Table_name
Users
Submitted_at description
User_id
Username
Created_at

TableColumns Synonyms

Column_id Synonym_id
Schema_id Entity_type
Column_name Entity_id
Data_type Synonym_text
description

QueryMapping
Mapping_id GeneratedQueries
Input_id Query_id
Intent_id Input_id
Schema_id Sql_query
Column_id Generated_at
status
1. Users Table

Stores information about users interacting with the system.

Column Name Data Type Description Constraints

user_id INT Unique identifier for the user Primary Key, Auto-Increment

username VARCHAR(50) User's name or alias NOT NULL, UNIQUE

created_at DATETIME Timestamp of account creation NOT NULL, Default: NOW()

Purpose: Tracks who is submitting queries for auditing or personalization.

2. UserInputs Table

Stores the raw naive input from users.

Column Name Data Type Description Constraints

input_id INT Unique identifier for the input Primary Key, Auto-Increment

user_id INT ID of the user submitting the input Foreign Key (Users.user_id)

input_text TEXT The naive natural language input NOT NULL

submitted_at DATETIME Timestamp of input submission NOT NULL, Default: NOW()

Purpose: Logs every user query for processing and historical analysis.

3. DatabaseSchema Table

Stores metadata about the target database schema that the SQL queries will interact with.

Column Name Data Type Description Constraints

schema_id INT Unique identifier for the schema Primary Key, Auto-Increment

table_name VARCHAR(50) Name of the table in the database NOT NULL

description TEXT Human-readable description of table NULLABLE

Purpose: Provides a reference for the tables available in the database.

4. TableColumns Table
Details the columns within each table of the database.

Column Name Data Type Description Constraints

Unique identifier for the


column_id INT Primary Key, Auto-Increment
column

ID of the table this column Foreign Key


schema_id INT
belongs to (DatabaseSchema.schema_id)

column_name VARCHAR(50) Name of the column NOT NULL

data_type VARCHAR(20) Data type (e.g., INT, VARCHAR) NOT NULL

description TEXT Human-readable description NULLABLE

Purpose: Maps column names and types for query generation and validation.

5. Synonyms Table

Stores natural language synonyms or aliases for tables and columns to aid in mapping naive input.

Column Name Data Type Description Constraints

Primary Key, Auto-


synonym_id INT Unique identifier for the synonym
Increment

ENUM('table',
entity_type Type of entity (table or column) NOT NULL
'column')

entity_id INT ID of the table or column NOT NULL

Natural language alias (e.g., "name" for


synonym_text VARCHAR(50) NOT NULL, UNIQUE
"customer_name")

Purpose: Helps interpret user input by linking common terms to schema elements (e.g., "price" →
unit_price).

6. Intents Table

Defines possible query intents (e.g., retrieve, insert, update) to classify user input.
Column Name Data Type Description Constraints

intent_id INT Unique identifier for the intent Primary Key, Auto-Increment

intent_name VARCHAR(20) Name of intent (e.g., SELECT, INSERT) NOT NULL, UNIQUE

description TEXT Explanation of the intent NULLABLE

Purpose: Categorizes the user's goal to guide SQL generation.

7. QueryMappings Table

Links user inputs to interpreted intents and schema elements.

Column Data
Description Constraints
Name Type

Unique identifier for the


mapping_id INT Primary Key, Auto-Increment
mapping

input_id INT ID of the user input Foreign Key (UserInputs.input_id)

intent_id INT ID of the detected intent Foreign Key (Intents.intent_id)

schema_id INT ID of the target table Foreign Key (DatabaseSchema.schema_id)

ID of the target column (if Foreign Key (TableColumns.column_id),


column_id INT
applicable) NULLABLE

Purpose: Records how the system interpreted the naive input in terms of intent and schema.

8. GeneratedQueries Table

Stores the SQL queries generated from user inputs.

Column Name Data Type Description Constraints

Unique identifier for the


query_id INT Primary Key, Auto-Increment
query

ID of the original user Foreign Key


input_id INT
input (UserInputs.input_id)

sql_query TEXT The generated SQL query NOT NULL

Timestamp of query
generated_at DATETIME NOT NULL, Default: NOW()
generation

ENUM('success', 'failed',
status Execution status NOT NULL, Default: 'pending'
'pending')

Purpose: Logs the final SQL output and its execution status for debugging and auditing.
Relationships

 Users → UserInputs: One-to-Many (a user can submit multiple inputs).

 UserInputs → QueryMappings: One-to-Many (an input can map to multiple schema


elements).

 UserInputs → GeneratedQueries: One-to-One (each input generates one SQL query).

 DatabaseSchema → TableColumns: One-to-Many (a table has multiple columns).

 Synonyms → DatabaseSchema or TableColumns: Many-to-One (multiple synonyms can map


to a table or column).

 QueryMappings → Intents, DatabaseSchema, TableColumns: Many-to-One (mappings


reference intents and schema elements).

Example Usage

Naive Input: "Show me all customer names and their orders."

1. UserInputs: Stores "Show me all customer names and their orders" with user_id and
submitted_at.

2. QueryMappings:

o Links to intent_id for "SELECT".

o Links to schema_id for "Customers" and "Orders" tables.

o Links to column_id for "customer_name" and "order_id".

3. GeneratedQueries: Stores SELECT customer_name, order_id FROM Customers JOIN Orders


ON Customers.id = Orders.customer_id.

You might also like