• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

PostgreSQL Command: DROP SEQUENCE

January 2, 2024

PostgreSQL Command: DROP SEQUENCE

In PostgreSQL, the DROP SEQUENCE command is used to remove a sequence from a database. A sequence is an object that generates a sequence of unique numbers. It is commonly used to generate primary key values for tables.

Syntax

The basic syntax for the DROP SEQUENCE command is as follows:

DROP SEQUENCE [IF EXISTS] sequence_name [CASCADE | RESTRICT];

Let’s break down the syntax:

  • IF EXISTS (optional): This clause allows you to avoid an error if the sequence does not exist.
  • sequence_name: Specifies the name of the sequence to be dropped.
  • CASCADE | RESTRICT (optional): These are the two options for handling dependent objects. If CASCADE is specified, all dependent objects (such as columns using the sequence) will also be dropped. If RESTRICT is specified, the command will fail if there are any dependent objects.

Examples

Let’s look at some examples to understand how the DROP SEQUENCE command works.

Example 1: Basic Usage

Suppose we have a sequence named customer_id_seq that we want to remove from the database. We can use the following command:

DROP SEQUENCE customer_id_seq;

This command will drop the customer_id_seq sequence from the database.

Example 2: Handling Dependent Objects

Let’s say we have a table named customers with a column named customer_id that uses the customer_id_seq sequence. If we try to drop the sequence without handling the dependent objects, we will get an error:

ERROR: cannot drop sequence customer_id_seq because other objects depend on it
DETAIL: default for table customers column customer_id depends on sequence customer_id_seq
HINT: Use DROP ... CASCADE to drop the dependent objects too.

To drop the sequence along with its dependent objects, we can use the CASCADE option:

DROP SEQUENCE customer_id_seq CASCADE;

This command will drop the customer_id_seq sequence and the customers table along with its dependent objects.

Summary

The DROP SEQUENCE command in PostgreSQL allows you to remove a sequence from a database. It follows a simple syntax, where you specify the name of the sequence to be dropped. You can also handle dependent objects using the CASCADE or RESTRICT options. Understanding how to use this command is essential for managing sequences effectively in PostgreSQL.

For more information about VPS hosting services, consider checking out Server.HK. They offer reliable and high-performance VPS solutions for your hosting needs.

Recent Posts

  • How to Deploy a Node.js Application on Hong Kong VPS: Complete Guide
  • How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  • How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  • CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  • Top 5 Use Cases for a Hong Kong Dedicated Server in 2026

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot