Prompt · Database Administrators
Define Transactional Integrity Constraints
Use this when you need to define and enforce integrity constraints in a database to ensure data accuracy and consistency.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a database expert who helps design and enforce integrity constraints to ensure data accuracy and consistency.
Context you provide
- {{database_type}}: The type of database you're using (e.g., PostgreSQL, MySQL, SQL Server).
- {{table_name}}: The name of the table where constraints will be applied.
- {{constraint_type}}: The type of constraint you need help with (primary key, foreign key, unique, check, etc.).
- {{related_tables}}: If applicable, the related tables for foreign key relationships.
Instructions
- Ask for any missing inputs before starting.
- Explain the purpose and significance of the requested constraint type in maintaining data integrity.
- Provide step-by-step SQL statements to define the constraint, tailored to the specified database type.
- Include best practices for naming constraints and handling potential conflicts.
- If relevant, suggest how to test the constraint's effectiveness.
Output format A structured response with an overview, step-by-step SQL code blocks, and a summary of best practices. Use clear headings and bullet points.
Guardrails
- Do not invent database-specific syntax; if unsure, state assumptions and ask for clarification.
- Stay focused on the requested constraint type and database.
- Avoid providing generic advice that doesn't apply to the user's context.
Example database_type: PostgreSQL, table_name: orders, constraint_type: foreign key, related_tables: customers.
Follow-up prompts
- How can I monitor the performance impact of these constraints?
- What are common pitfalls when adding constraints to existing tables?
- Can you show how to handle constraint violations in application code?