SQL Table Delete and Truncate, Schemas and Synonyms

8
Presented by Aaron Buma

Transcript of SQL Table Delete and Truncate, Schemas and Synonyms

Page 1: SQL Table Delete and Truncate, Schemas and Synonyms

Presented by Aaron Buma

Page 2: SQL Table Delete and Truncate, Schemas and Synonyms

Table Data OperationsDELETE TRUNCATE

You can filter on what you DELETE

IDENTITY counters are not reset

Can be rolled back (each row logged)

You can’t filter, it clears whole table

Resets the IDENTITY counter

Cannot be rolled back (only page destruction logged)

Can’t do if: there are triggers, table is in log shipping or if it has FK’s

Page 3: SQL Table Delete and Truncate, Schemas and Synonyms

Schemas Default is “dbo”

Ability to group objects

A layer of permissions between Database and Object levels

Clean Code – Intent through name

Duplicate object names, but in different schemas

Page 4: SQL Table Delete and Truncate, Schemas and Synonyms

Schemas – Can be applied to: Table

View

Stored procedure

Function (all 3 types)

CLR table-valued function

CLR stored procedure

CLS scalar function

CLR aggregate function

Extended SPROC

Page 5: SQL Table Delete and Truncate, Schemas and Synonyms

Synonyms Create a short-hand name to a fully qualified object

Databasename. SchemaName.tableOrders -> orders SELECT * FROM Databasename. SchemaName.tableOrders;

SELECT * FROM orders;

Double-Edged Sword – Abstracts underlying structure

Extra level of complexity

Page 6: SQL Table Delete and Truncate, Schemas and Synonyms

Synonyms – Data Permissions CONTROL

DELETE

EXECUTE

INSERT

SELECT

UPDATE

TAKE OWNERSHIP

VIEW DEFINITION

Page 7: SQL Table Delete and Truncate, Schemas and Synonyms

Synonyms - Limitations

Loosely bound – no warnings of references with delete

Can’t be referenced in a DDL

No Chaining

When being created, the object it is referencing doesn’t have to exist

Page 8: SQL Table Delete and Truncate, Schemas and Synonyms

Demo