Skip to main content
added 129 characters in body
Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

In this case, the synonym should be properly deleted. If, if not, it cannot be used but still exists on sys.synonyms catalog.

You can check it running next script:

IF OBJECT_ID('T1') IS NOT NULL
    DROP TABLE T1;
GO

IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

CREATE TABLE T1(f1 int);
GO

INSERT INTO T1 VALUES (1),(2),(3);
GO

CREATE SYNONYM NEW_T1 FOR T1;
GO

SELECT * FROM NEW_T1;
GO

f1
-----------
1
2
3

DROP TABLE T1;
GO

SELECT * FROM NEW_T1;
GO

Msg 5313, Level 16, State 1, Line 23
Synonym 'NEW_T1' references an invalid object.

SELECT name, object_id FROM sys.synonyms WHERE name = 'NEW_T1';
GO

name        object_id
------      --------------
NEW_T1      1463676262


IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

In this case, synonym should be properly deleted. If not, it cannot be used but still exists on sys.synonyms catalog.

You can check it running next script:

IF OBJECT_ID('T1') IS NOT NULL
    DROP TABLE T1;
GO

IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

CREATE TABLE T1(f1 int);
GO

INSERT INTO T1 VALUES (1),(2),(3);
GO

CREATE SYNONYM NEW_T1 FOR T1;
GO

SELECT * FROM NEW_T1;
GO

f1
-----------
1
2
3

DROP TABLE T1;
GO

SELECT name, object_id FROM sys.synonyms WHERE name = 'NEW_T1';
GO

name        object_id
------      --------------
NEW_T1      1463676262


IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

In this case the synonym should be properly deleted, if not, it cannot be used but still exists on sys.synonyms catalog.

You can check it running next script:

IF OBJECT_ID('T1') IS NOT NULL
    DROP TABLE T1;
GO

IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

CREATE TABLE T1(f1 int);
GO

INSERT INTO T1 VALUES (1),(2),(3);
GO

CREATE SYNONYM NEW_T1 FOR T1;
GO

SELECT * FROM NEW_T1;
GO

f1
-----------
1
2
3

DROP TABLE T1;
GO

SELECT * FROM NEW_T1;
GO

Msg 5313, Level 16, State 1, Line 23
Synonym 'NEW_T1' references an invalid object.

SELECT name, object_id FROM sys.synonyms WHERE name = 'NEW_T1';
GO

name        object_id
------      --------------
NEW_T1      1463676262


IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO
Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

In this case, synonym should be properly deleted. If not, it cannot be used but still exists on sys.synonyms catalog.

You can check it running next script:

IF OBJECT_ID('T1') IS NOT NULL
    DROP TABLE T1;
GO

IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO

CREATE TABLE T1(f1 int);
GO

INSERT INTO T1 VALUES (1),(2),(3);
GO

CREATE SYNONYM NEW_T1 FOR T1;
GO

SELECT * FROM NEW_T1;
GO

f1
-----------
1
2
3

DROP TABLE T1;
GO

SELECT name, object_id FROM sys.synonyms WHERE name = 'NEW_T1';
GO

name        object_id
------      --------------
NEW_T1      1463676262


IF OBJECT_ID('NEW_T1') IS NOT NULL
    DROP SYNONYM NEW_T1;
GO