To get the materials for this presentation: http://www.aaronbuma.com/2015/04/sql-table-data-operations-schemas-and-synonyms/
For any of my previous presentations visit: http://www.aaronbuma.com/category/sql-training/
2. Table Data Operations
DELETE 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
3. 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
4. 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
5. 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
6. Synonyms – Data Permissions
CONTROL
DELETE
EXECUTE
INSERT
SELECT
UPDATE
TAKE OWNERSHIP
VIEW DEFINITION
7. 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