SQL Table Delete and Truncate, Schemas and Synonyms
-
Upload
aaron-buma -
Category
Software
-
view
736 -
download
1
Transcript of SQL Table Delete and Truncate, Schemas and Synonyms
![Page 1: SQL Table Delete and Truncate, Schemas and Synonyms](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/1.jpg)
Presented by Aaron Buma
![Page 2: SQL Table Delete and Truncate, Schemas and Synonyms](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/6.jpg)
Synonyms – Data Permissions CONTROL
DELETE
EXECUTE
INSERT
SELECT
UPDATE
TAKE OWNERSHIP
VIEW DEFINITION
![Page 7: SQL Table Delete and Truncate, Schemas and Synonyms](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/7.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022073118/55a6c7471a28ab98048b468f/html5/thumbnails/8.jpg)
Demo