Synonyms Flashcards

1
Q

What is a synonym?

A

It’s basically an alias for an object name. Much like you would alias a column name.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Syntax to create a synonym

A
USE TSQL2012
GO
CREATE SYNONYM dbo.Categories FOR Production.Categories;
GO

dbo.Categories synonym name
Production.Categories object you are creating a synonym for

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Does the object the synonym will be an alias for need to exist when the synonym is created?

A
  • No. Because of the late binding of synonyms
  • When you actually use the synonym in a tsql statement, SQL Server will check for the objects existence.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What rules must be complied with when naming a synonym?

A

Rules for tsql identifiers

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do synonyms store any data or code?

A

No

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If you don’t specify a schema when you create the synonym, what schema will it be assigned to?

A

The default schema associated with the user name.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What 5 types of objects can synonyms be used for?

A
  1. Tables, including temporary tables
  2. Views
  3. User-defined functions (Scalar, table-valued, inline)
  4. Stored procs (T-SQL, extended stored procedures and replication filter procedures)
  5. CLR Assemblies (stored procedures; table-valued, scalar, and aggregate functions)

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can synonyms refer to synonyms?

A

No! They can only refer to database objects.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Where can you use synonyms?

A

In TSQL statements that refer to the types of objects that synonyms stand for.

EXECUTE
SELECT
INSERT
UPDATE
DELETE

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What statement can you not reference a synonym in?

A

ALTER. You must reference the base object instead.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you ALTER a synonym itself?

A
  • You can’t. There is no ALTER SYNONYM statement.
  • You have to drop it and recreate it.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Statement to drop synonym

A

DROP SYNONYM synonym_name

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Does a synonym have to refer to an object in the same database it is created in?

A

No. It can refer to an object in another database, in addition to objects referenced by linked servers.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can an object be dropped even if there is a synonym that refers to it?

A
  • Yes, unfortunately
  • There is nothing similar to SCHEMABINDING for synonyms

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is one advantage of being able to create a synonym for an object that doesn’t yet exist?

A
  • You can use a single synonym for many different objects. Just recreate the synonym for each object as you need it.
  • Or you could create the same synonym in multiple databases to reference the same object.

SQL Server 70-461 09-02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What permission must you have to create a synonym?

A

CREATE SYNONYM

SQL Server 70-461 09-02

17
Q

If you have CREATE SYNONYM permission, can you grant other users permission to the synonym?

A

Yes. You could grant permissions such as EXECUTE or SELECT depending on the type of object the synonym stands for.

SQL Server 70-461 09-02