Skip to main content
data advanced

Normalize Database Table Structure

AI prompt to analyze and normalize database table structures, eliminate redundancy, and create proper relationships for optimal performance.

Works with: chatgptclaudegemini

Prompt Template

You are a database design expert specializing in normalization. Analyze the following table structure and normalize it according to database normalization principles (1NF, 2NF, 3NF, and BCNF where applicable). Original table structure: [TABLE_STRUCTURE] Target normalization level: [NORMALIZATION_LEVEL] Database type: [DATABASE_TYPE] Please provide: 1. **Analysis of Current Issues**: Identify normalization violations, redundancy problems, and potential anomalies in the current structure. 2. **Normalized Schema Design**: Create the normalized table structure with: - Proper table names following naming conventions - Appropriate data types for each field - Primary keys and foreign key relationships - Indexes for performance optimization 3. **SQL DDL Statements**: Provide complete CREATE TABLE statements for the normalized schema, including constraints and relationships. 4. **Data Migration Strategy**: Explain how to migrate existing data from the denormalized structure to the new normalized tables, including any necessary transformation logic. 5. **Performance Considerations**: Discuss the trade-offs between normalization benefits (reduced redundancy, data integrity) and potential performance implications (joins, query complexity). 6. **Documentation**: Create a brief explanation of the relationships between tables and the reasoning behind the normalization decisions. Ensure all suggestions follow best practices for [DATABASE_TYPE] and maintain data integrity while optimizing for the specified use case.

Variables to Customize

[TABLE_STRUCTURE]

The current table structure with column names, data types, and sample data

Example: customers_orders (customer_id, customer_name, customer_email, customer_phone, order_id, order_date, product_name, product_price, quantity, category)

[NORMALIZATION_LEVEL]

The target normalization form to achieve

Example: Third Normal Form (3NF)

[DATABASE_TYPE]

The specific database management system being used

Example: PostgreSQL

Example Output

**Analysis of Current Issues:** The customers_orders table violates multiple normalization principles: - 1NF violation: Repeating customer information for each order - 2NF violation: Non-key attributes depend on partial keys - Data redundancy in customer details and product information **Normalized Schema Design:** *customers table:* - customer_id (PRIMARY KEY) - customer_name - customer_email - customer_phone *products table:* - product_id (PRIMARY KEY) - product_name - product_price - category_id (FOREIGN KEY) *orders table:* - order_id (PRIMARY KEY) - customer_id (FOREIGN KEY) - order_date *order_items table:* - order_item_id (PRIMARY KEY) - order_id (FOREIGN KEY) - product_id (FOREIGN KEY) - quantity **SQL DDL Statements:** ```sql CREATE TABLE customers ( customer_id SERIAL PRIMARY KEY, customer_name VARCHAR(100) NOT NULL, customer_email VARCHAR(255) UNIQUE, customer_phone VARCHAR(20) ); CREATE TABLE categories ( category_id SERIAL PRIMARY KEY, category_name VARCHAR(50) NOT NULL ); ``` This normalized structure eliminates redundancy and ensures data integrity.

Pro Tips for Best Results

  • Always start by identifying functional dependencies between columns to understand normalization violations
  • Consider the specific query patterns and performance requirements when deciding on normalization level
  • Include proper indexing strategy for foreign keys to maintain query performance
  • Document the relationships clearly to help future developers understand the schema design
  • Test the migration strategy with a subset of data before applying to production tables

Tags

Want 500+ Expert Prompts?

Get the Premium Prompt Pack — organized, tested, and ready to use.

Get it for $29

Related Prompts You Might Like