Synonyms in SQL are alternative names assigned to database objects, allowing users and applications to access those objects without referring to their original names every time. They can make database queries easier to read, simplify access to objects in different schemas, and reduce the need to change SQL statements when an object’s underlying name or location changes.
In database terminology, a synonym is not a synonym in the ordinary vocabulary sense. It is a database object that acts as an alternative reference to another object, such as a table, view, sequence, or stored procedure, depending on the database management system.
Understanding SQL synonyms is useful for database developers, administrators, and anyone working with large databases.
What Are Synonyms in SQL?
A synonym in SQL is a database object that provides an alternative name for another database object.
Instead of referencing an object using its complete original name, users can reference it through its synonym.
For example, imagine a database table called:
company_database.employee_records
A database administrator could create a synonym named:
employees
Users with the appropriate permissions could then access the table using the shorter name.
SELECT *
FROM employees;
Rather than writing:
SELECT *
FROM company_database.employee_records;
The synonym provides a convenient alternative name without creating another copy of the original table.
Important: SQL synonyms are database-specific features. Oracle Database, Microsoft SQL Server, and other database systems differ in their syntax, supported object types, permissions, and implementation.
Why Are Synonyms Used in SQL?
Synonyms are primarily used to simplify database object references and provide flexibility when accessing database objects.
Here are their most useful applications.
1. Simplifying Long Object Names
Database objects sometimes have lengthy names or require schema-qualified references.
A synonym provides a shorter alternative.
For example:
SELECT *
FROM sales_department.customer_information;
With an appropriate synonym:
SELECT *
FROM customers;
This can make frequently used queries easier to understand and maintain.
2. Accessing Objects Across Schemas
Large databases often contain multiple schemas.
A schema is a logical collection of database objects, such as tables, views, and procedures.
A synonym can provide a convenient name for an object located in another schema.
For example, a user working in the reporting schema might need access to a table in the finance schema.
Instead of repeatedly referencing the complete object name, the user can use an appropriate synonym.
The user must still have the necessary privileges to access the underlying object.
3. Improving Database Application Flexibility
Applications often contain SQL statements that reference database objects directly.
If an object’s name or location changes, queries that use its original name may need updating.
A synonym can provide an additional layer of naming flexibility.
For example, an application might reference:
SELECT *
FROM customer_data;
The synonym could point to an underlying object in a different schema.
If the underlying object is relocated or replaced, an administrator may be able to update the synonym instead of modifying every application query.
However, this depends on the database system and the nature of the change. Synonyms do not automatically guarantee that applications will remain compatible.
4. Making SQL Queries Easier to Read
Shorter object names can make SQL statements more readable, particularly when queries involve several tables or schemas.
For example:
SELECT customer_name, order_total
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id;
Using meaningful synonyms can help developers work with complex database structures.
Types of Synonyms in SQL
The types of synonyms depend on the database management system.
Oracle Database and Microsoft SQL Server, for example, support different synonym features and terminology.
1. Private Synonyms
A private synonym is available within the relevant database user’s schema.
In Oracle Database, a private synonym is created for a particular user and can provide an alternative name for an existing database object.
Example:
CREATE SYNONYM employees
FOR hr.employee_records;
This creates a synonym named employees that refers to hr.employee_records.
The user must have the required privileges to create the synonym and access the underlying object.
Private synonyms are useful when a particular user needs a shorter or more convenient reference to a database object.
2. Public Synonyms
A public synonym is available for use by database users, subject to applicable permissions and name-resolution rules.
In Oracle Database, a public synonym can be created using:
CREATE PUBLIC SYNONYM employees
FOR hr.employee_records;
This makes the synonym available as a database-wide name.
However, creating a public synonym does not automatically give every user permission to access the underlying object.
Users still need the appropriate privileges.
Private vs. public synonyms
| Feature | Private synonym | Public synonym |
|---|---|---|
| Availability | Associated with a particular schema | Available across the database |
| Creation | CREATE SYNONYM | CREATE PUBLIC SYNONYM |
| Main purpose | Simplify access for a particular user | Provide a shared object name |
| Access permissions | Still required | Still required |
| Typical use | Individual or application-specific access | Shared database references |
These terms are particularly associated with Oracle Database. SQL Server has its own synonym implementation and does not use Oracle’s private/public synonym distinction.
How to Create a Synonym in SQL
The exact syntax varies between database systems.
The following examples demonstrate synonym creation in Oracle Database and Microsoft SQL Server.
Creating a Synonym in Oracle Database
Oracle supports private and public synonyms.
Basic syntax:
CREATE SYNONYM synonym_name
FOR object_name;
For example:
CREATE SYNONYM employees
FOR hr.employee_records;
After creating the synonym, an authorized user can reference the object through:
SELECT *
FROM employees;
The synonym points to the original object. It does not create a new table or duplicate its records.
Creating a public synonym:
CREATE PUBLIC SYNONYM employees
FOR hr.employee_records;
This creates a public synonym named employees.
Creating a Synonym in SQL Server
Microsoft SQL Server also supports synonyms.
Its syntax is:
CREATE SYNONYM synonym_name
FOR object_name;
For example:
CREATE SYNONYM employees
FOR HumanResources.dbo.EmployeeRecords;
The synonym can then be used in a query:
SELECT *
FROM employees;
SQL Server synonyms can reference supported database objects, including objects located in other databases or on linked servers.
The referenced object does not necessarily need to exist when the synonym is created. However, the reference must resolve successfully when the synonym is used.
How to Use Synonyms in SQL Queries
Once a synonym has been created, it can be used in place of the referenced object name.
For example, suppose the original table is:
CREATE TABLE employee_records (
employee_id INT,
employee_name VARCHAR(100),
department VARCHAR(50)
);
A synonym can be created in a database system that supports the relevant syntax:
CREATE SYNONYM employees
FOR employee_records;
You can then query the table through its synonym:
SELECT *
FROM employees;
You can also retrieve particular columns:
SELECT employee_name, department
FROM employees;
The synonym serves as an alternative reference to the same underlying table.
It does not independently store employee information.
Note: The table definition above is illustrative. The exact synonym creation syntax and supported operations depend on the database platform.
Synonyms in SQL: Examples
The following examples demonstrate common situations in which synonyms are useful.
Example 1: Shortening a Table Name
Suppose a table has the following name:
company_data.customer_transaction_history
You can create a synonym:
CREATE SYNONYM transactions
FOR company_data.customer_transaction_history;
You can then use:
SELECT *
FROM transactions;
This avoids repeatedly typing the longer object name.
Example 2: Referencing an Object in Another Schema
Suppose the HR schema contains a table named employee_records.
An Oracle user can create a synonym:
CREATE SYNONYM staff
FOR hr.employee_records;
The user can then run:
SELECT *
FROM staff;
This makes it easier to reference an object outside the user’s own schema.
Example 3: Using a Synonym in an Application
Imagine an application that frequently retrieves product information.
The original table is:
inventory.product_catalog
An administrator creates a synonym:
CREATE SYNONYM products
FOR inventory.product_catalog;
The application can use:
SELECT product_name, price
FROM products;
This provides a shorter object reference.
If the underlying database object needs to be relocated, the synonym may provide a way to redirect references, depending on the database platform and application requirements.
ALSO READ: 25 Synonyms of Conquest: Meanings, Differences, and Examples
How to Drop or Delete a Synonym in SQL
A synonym can be removed without deleting the original database object.
The command depends on the database system.
Dropping a Synonym in Oracle
To remove a private synonym:
DROP SYNONYM employees;
To remove a public synonym:
DROP PUBLIC SYNONYM employees;
Dropping a Synonym in SQL Server
SQL Server uses:
DROP SYNONYM employees;
Dropping a synonym removes the alternative reference, not the underlying table, view, or other referenced object.
This distinction is important because deleting a synonym should not be confused with deleting the database object itself.
ALSO CHECKOUT: Synonyms of Glasses: 15 Alternatives and Their Meanings
Synonyms vs. Aliases in SQL
Synonyms and aliases may appear similar because both provide alternative names. However, they serve different purposes.
A synonym is a database object that provides an alternative name for another database object.
An alias is generally a temporary alternative name assigned within a particular SQL statement.
For example:
SELECT employee_name
FROM employee_records AS e;
Here, e is a table alias.
It exists within the scope of that query.
By comparison:
CREATE SYNONYM employees
FOR employee_records;
This creates a database synonym that can be referenced in separate SQL statements.
| Feature | Synonym | Alias |
|---|---|---|
| Purpose | Alternative database object name | Alternative name within a query |
| Scope | Database object scope | SQL statement scope |
| Created using | CREATE SYNONYM | Usually defined in a query |
| Persistent | Yes, until dropped | No, generally limited to the statement |
| Main benefit | Simplifies object references | Improves query readability |
For example, a synonym might shorten a long table reference, while an alias might shorten the table name within a complex join.
They are not interchangeable database features.
Advantages of Synonyms in SQL
Synonyms provide several practical benefits.
Simplified Object References
They allow developers to use shorter and more convenient names instead of repeatedly writing long schema-qualified object names.
Easier Cross-Schema References
They can simplify references to objects belonging to other schemas or databases, depending on the database platform.
Greater Naming Flexibility
They can provide a stable reference point when the underlying object name or location needs to change.
Improved Query Readability
Meaningful synonym names can make SQL statements easier to understand.
Convenient Application Development
Applications can reference synonyms rather than embedding certain underlying object names throughout their code.
However, synonyms are not a replacement for good database design or access-control practices.
Disadvantages and Limitations of SQL Synonyms
Although synonyms are useful, they also have limitations.
1. They Do Not Store Data
A synonym is not a table and does not contain independent records.
It simply references another database object.
2. They Do Not Automatically Grant Permissions
Creating a synonym does not give users access to the underlying object.
The required database privileges must still be granted.
3. They Can Make Object References Less Transparent
A developer may see a synonym in a query without immediately knowing which underlying object it references.
This can make database troubleshooting more difficult if synonyms are poorly documented.
4. They Do Not Guarantee That Referenced Objects Exist
Some database systems allow synonyms to be created before their target objects exist.
A query using such a synonym may fail if the referenced object cannot be resolved.
5. They Are Database-Specific
Synonym support, syntax, permissions, and supported object types differ between database management systems.
A synonym created in one database platform cannot automatically be transferred to another without considering the target system’s capabilities.
Common Mistakes When Using Synonyms in SQL
Understanding the limitations of synonyms helps prevent common database errors.
Confusing Synonyms With Tables
A synonym is not a separate table.
It does not contain its own data and does not automatically create a copy of the referenced object.
Assuming Synonyms Grant Access
A public synonym may make an object easier to reference, but it does not automatically grant every database user permission to access that object.
Confusing Synonyms With Aliases
A synonym is a database object, whereas an alias is generally limited to an individual SQL statement.
Using these terms interchangeably can cause confusion when discussing database structures.
Assuming All Database Systems Use the Same Syntax
Oracle Database and SQL Server both support synonyms, but their implementations and administrative details are not identical.
Always use the syntax appropriate to the database management system.
Forgetting That Synonyms Can Become Invalid
A synonym may stop working if its referenced object is removed, renamed, or becomes inaccessible.
Database administrators should monitor dependencies and update affected references when necessary.
Frequently Asked Questions About Synonyms in SQL
1. What is a synonym in SQL in simple words?
A synonym in SQL is an alternative name for an existing database object. It allows users to reference a table, view, or another supported object using a different name.
2. What is the main purpose of synonyms in SQL?
The main purpose is to simplify database object references. Synonyms can shorten long names, simplify cross-schema access, and provide greater flexibility when working with database objects.
3. What are the two types of synonyms in Oracle SQL?
Oracle Database supports two main types:
- Private synonyms: Associated with a particular database user’s schema.
- Public synonyms: Available for use across the database, subject to applicable access privileges and name-resolution rules.
4. Do synonyms create duplicate tables?
No. A synonym does not duplicate the underlying table or its records. It simply provides another name for the referenced object.
5. What is the difference between a synonym and a view?
A synonym is an alternative reference to an existing database object.
A view is a database object defined by a query that presents data from one or more underlying sources.
A view can provide a customized representation of data, while a synonym primarily provides another name for an existing object.
6. Can a synonym refer to a table in another database?
Yes, depending on the database management system.
For example, SQL Server supports synonyms that reference supported objects in other databases and on linked servers.
7. Does dropping a synonym delete the original table?
No. Dropping a synonym removes the alternative name, not the underlying table or other referenced object.
8. Are synonyms supported in all SQL databases?
No. Synonym support varies between database systems. Oracle Database and Microsoft SQL Server support synonyms, but their syntax and capabilities differ.
Conclusion
Synonyms in SQL provide alternative names for database objects, making it easier to reference tables, views, and other supported objects.
They are particularly useful for simplifying long object names, accessing objects across schemas, improving query readability, and providing flexibility in database applications.
The most important distinction is that a synonym is not a duplicate table, a view, or a temporary query alias. It is a database object that points to another object.
Understanding this distinction helps developers and database administrators use synonyms effectively while avoiding common mistakes involving object references, permissions, and database dependencies.

