diff --git a/pkg/sql/drop_sequence.go b/pkg/sql/drop_sequence.go index d25c976310e9..506d452fbffa 100644 --- a/pkg/sql/drop_sequence.go +++ b/pkg/sql/drop_sequence.go @@ -107,6 +107,9 @@ func (p *planner) dropSequenceImpl( jobDesc string, behavior tree.DropBehavior, ) error { + if err := removeSequenceOwnerIfExists(ctx, p, seqDesc.ID, seqDesc.GetSequenceOpts()); err != nil { + return err + } return p.initiateDropTable(ctx, seqDesc, queueJob, jobDesc, true /* drainName */) } diff --git a/pkg/sql/logictest/testdata/logic_test/sequences b/pkg/sql/logictest/testdata/logic_test/sequences index f503ff0b1c29..2bf2292603f0 100644 --- a/pkg/sql/logictest/testdata/logic_test/sequences +++ b/pkg/sql/logictest/testdata/logic_test/sequences @@ -1081,3 +1081,17 @@ CREATE TABLE c(a INT DEFAULT(currval('currval_dep_test'))) statement error pq: cannot drop sequence currval_dep_test because other objects depend on it DROP SEQUENCE currval_dep_test + +subtest regression_50649 + +statement ok +CREATE TABLE t_50649(a INT PRIMARY KEY) + +statement ok +CREATE SEQUENCE seq_50649 OWNED BY t_50649.a + +statement ok +DROP SEQUENCE seq_50649 + +statement ok +DROP TABLE t_50649