DAT335 SQL Server 2000 Tips and Tricks: DBAs and Developers Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com

Slides:



Advertisements
Similar presentations
Batches, Scripts, Transactions-SQL Server 7. A batch is a set of Transact-SQL statements that are interpreted together by SQL Server. They are submitted.
Advertisements

Big Data Working with Terabytes in SQL Server Andrew Novick
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Database Optimization & Maintenance Tim Richard ECM Training Conference#dbwestECM Agenda SQL Configuration OnBase DB Planning Backups Integrity.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Introduction to Structured Query Language (SQL)
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Connect with life Vinod Kumar M Technology Evangelist | Microsoft
Managing and Monitoring SQL Server 2005 Shankar Pal Program Manager SQL Server, Redmond.
OFC324 Microsoft Project Server: Putting Enterprise Project Management (EPM) To Work Sam Brooks
DBA 322 Optimizing Stored Procedure Performance Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
DAT304 Leveraging XML and HTTP with Sql Server Irwin Dolobowsky Program Manager Webdata Group.
Overview What is SQL Server? Creating databases Administration Security Backup.
DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Monday, 13 October 2003 The Anatomy of a Data Modification Subset of: What everyone should know about Performance, Recovery & Logging Monday, 13 October.
Designing for Performance General Database Optimizations Presentation Highlight: The Anatomy of a Data Modification Wednesday, 12 November 2003 – 16:30-18:00.
OFC304 Excel 2003 Overview: XML Support Joseph Chirilov Program Manager.
OFC 200 Microsoft Solution Accelerator for Intranets Scott Fynn Microsoft Consulting Services National Practices.
DAT430 Extending SQL Server 2000 Functionality with User-Defined Functions: Hidden Tricks Fernando G. Guerrero S olid Q uality L earning
SEC303 Assessing and Managing Privacy in the Enterprise JC Cannon Privacy Strategist.
Company LOGO 1 Database Creation and Maintenance Jorge G. Martinez.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Copyright © 2013 Curt Hill Database Security An Overview with some SQL.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Understanding Logging & Recovery What Programmers Always Avoid Until it’s too Late! Kimberly L. Tripp Principal Mentor, Solid Quality Learning at
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
DBA 328 Designing for Performance: Optimization with Indexes Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com
DEV303 ASP.NET: Leveraging Visual Studio.NET For Web Projects Tony Goodhew Product Manager Microsoft Corp.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
DAT 332 SQL Server 2000 Data Transformation Services (DTS) Best Practices Euan Garden Product Unit Manager SQL Server Development Microsoft Corporation.
Praveen Srivatsa Director| AstrhaSoft Consulting blogs.asthrasoft.com/praveens |
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Connect with life Vinod Kumar Technology Evangelist - Microsoft
Connect with life Nauzad Kapadia Quartz Systems
IT System Administration Lesson 3 Dr Jeffrey A Robinson.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Danny Tambs – Senior Consultant Microsoft.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.
OFC311 Developing Microsoft Office InfoPath 2003 Solutions: Technical Drilldown Part 1 Tudor Toma Group Program Manager Office Microsoft Corporation.
Praveen Srivatsa Director| AstrhaSoft Consulting blogs.asthrasoft.com/praveens |
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Advanced Database & Client Server Introduction to MS SQL Server 2000 and Transact SQL -
Enterprise Database Systems Introduction to SQL Server Dr. Georgia Garani Dr. Theodoros Mitakos Technological.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
In this session, you will learn to: Manage databases Manage tables Objectives.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
SQL Database Management
Database Administration
Physical Changes That Don’t Change the Logical Design
6/16/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Introduction to SQL Server Management for the Non-DBA
TechEd /24/2018 8:21 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Contents Preface I Introduction Lesson Objectives I-2
Chapter 11 Managing Databases with SQL Server 2000
5/8/2019 3:20 AM bQuery-Tool 3.0 A new and elegant way to create queries and ad-hoc reports on your Baan/Infor ERP LN data. This Baan session is a query.
Presentation transcript:

DAT335 SQL Server 2000 Tips and Tricks: DBAs and Developers Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com SYSolutions, Inc. – SQLSkills.com

Introduction Kimberly L. Tripp, SQL Server MVP Principal Mentor, Solid Quality Learning * In-depth, high quality training around the world! Content Manager for Writer/Editor for TSQL Solutions/SQL Mag and Consultant/Trainer/Speaker Coauthor for MSPress title: SQL Server 2000 High Availability Presenter/Technical Manager for SQL Server 2000 High Availability Overview DVD Very approachable. Please ask me questions!

Overview Saving Production Data Case Sensitive Searching Creating Cool Constraints All About Raiserror Minimizing Transactional Code VLDB Backup Best Practices – File/Filegroup Backup/Restore

Saving Production Data from Production DBAs Data Disaster Issues Schemabinding Create SCHEMABOUND Views

Data Disaster Issues Unexpected UPDATEs/DELETEs Minimize User’s permissions/direct access to base tables Use stored procedures for consistency/integrity Unexpected Table Drop Foreign Keys – protect a table from being dropped ONLY when other tables REFERENCE it… What about a Sales type of table? CustomerID SalesPersonID ProductID Sales CustomerID Customers EmployeeID Employees ProductID ?!? DROP TABLE Sales

Schemabinding Solid Dependency Chains – Used to more permanently associate objects All Objects on which a schemabound object is bound – must also be bound All Objects must be referenced using two-part naming Must explicitly name columns in object (no *) No objects (or columns in definition of bound object) can be modified or dropped unless the object or schemabinding are removed! CustomerID SalesPersonID ProductID Sales DROP TABLE Sales Server: Msg 3729, Level 16, State 1, Line 1 Cannot DROP TABLE 'Sales' because it is being referenced by…

Create SCHEMABOUND Views Use WITH SCHEMABINDING in View Definition CREATE VIEW Sales_PreventTableDropView WITH SCHEMABINDING AS SELECT SalesID FROM dbo.Sales Create Views on All objects you want to protect Review TSQL Tutor Quick Tip, InstantDoc ID# for code to automate the creation! or

Case Sensitive Searching Sort Order Concepts Sort Order Options Case Sensitive Searching

Sort Order Options To see the list of collations SELECT * FROM ::fn_helpcollations() To see the server's setting sp_helpsort To see the database's setting sp_helpdb dbname To see the table's setting (for each column) sp_help tname For more information, check out these BOL topics: COLLATE "Specifying Collations"

Sort Order Concepts May be changed at any point in chain Different options offer different gains – most in language sorting, some in performance Can assign on the fly for just a single query – or within a view for subsequent use Can index the view for speed Full benefits of Indexed Views in Enterprise Edition only, see the whitepaper (listed in resources) for specific details. Windows Install SQL Server Install Database Creation Table Creation Query Usage I n h e r i t e d } Use COLLATE option to change

Case Sensitive Searching CREATE VIEW AuthorsLastNameCaseSensitive AS SELECT au_lname COLLATE Latin1_General_CS_AS_KS_WS AS LastName FROM authors go -- Select from the View SELECT * FROM AuthorsLastNameCaseSensitive WHERE LastName= 'ringer' -- 0 Rows SELECT * FROM AuthorsLastNameCaseSensitive WHERE LastName= 'Ringer' -- 2 Rows!!! Performance will NOT be good on large data sets. Consider creating an index on the AuthorsLastNameCaseSensitive View IF BOTH case-sensitive and case-insensitive searching is a common requirement for this table. See the Whitepaper: Improving Performance with Microsoft SQL Server 2000 Indexed Views.

Creating Cool Constraints DEFAULT Constraints CHECK Constraints DO NOT USE WITH NOCHECK

DEFAULT Constraints Need to adhere to CHECK constraints, if one exists Must be compatible with column datatype Can use system or user-defined functions! InsertedByvarchar(60)NOT NULL CONSTRAINT EmployeeInsertedByDflt DEFAULT host_name() + '\' + suser_sname() + '\' + user_name() RoadRunnerKT\domain\kimberly\kim RoadRunnerKT\sa\dbo

Check Constraints (optimizer) All data will be checked on INSERT/UPDATE Pattern CHECK (Phone LIKE ‘(___) ___-____’) *Range* CHECK (Salary < ) The only operators supported for increased performance gains are: BETWEEN, AND, OR,, >=, =. Others are supported for data integrity purposes only. List CHECK (Country Code IN (‘US’, ‘AU’, ‘GB’, ‘FR’)) Added during CREATE TABLE Add later using ALTER TABLE But what about the existing data?

DO NOT USE WITH NOCHECK ALTER TABLE with CHECK – all existing data is checked and verified ALTER TABLE with NOCHECK – speeds up the creation BUT there are no performance gains for later use of the constraint Scenario Charge Table 1.6 Million Rows Constraint added with NOCHECK (ChargeAmt < 5000) SELECT * FROM Charge WHERE ChargeAmt > yields 9305 I/O Constraint added with CHECK (ChargeAmt < 5000) SELECT * FROM Charge WHERE ChargeAmt > yields 0 I/O

All About RAISERROR RAISERROR Syntax Reviewed Parameterized Messages

RAISERROR Syntax Reviewed RAISERROR(Error, Severity, State [, VariableList] WITH LOG Error String – can be a parameterized or fixed string of up to 400 characters. When parameterized the variables need to follow using VariableList Number System messages < = default number for string messages User defined messages > 50000, added with sp_addmessage VariableList – Error string must follow a specific format using placeholders for variables. Variables can follow two formats – by position or by number Examples coming up!

RAISERROR Syntax Reviewed RAISERROR(Error, Severity, State [, VariableList]) WITH LOG Severity 1-9 Error number in black with error message is NOT set Severity 10 ONLY the error message is returned, no error number is returned is NOT set Severity Error number in red with error message is set Severity 15 Error number in red with error message is set Severity 16 Error number in red with error message is set For more information, see the BOL topic “Error Message Severity Levels” Informational Warning Error When Logged to the Event Viewer Application Log

RAISERROR Syntax Reviewed RAISERROR(Error, Severity, State [, VariableList] WITH LOG State Usually avoided by using 1 Virtually no use…except one! Using osql.exe and a state of 127 you can control the termination of a complex script before it executes in the wrong database! IF DATABASEPROPERTYEX('DBName', 'COLLATION') IS NULL BEGIN RAISERROR ('Error Message.', 16, 127) END

Parameterized Messages exec = = = 'Value %s is invalid. Procedure %s expected a value of TRUE or FALSE for parameter %s. The default is = = 'FALSE' go exec = = = 'La valeur %s est inadmissible. Le procédé %s s''est attendu à une valeur de VRAI ou de FAUX pour le paramètre %s. Le défaut est %s.' -- translation provided by = = 'FALSE' go RAISERROR(900001, 16, 1, ‘string’, ‘string’, ‘string’,‘string’) WITH LOG

Minimize Transactional Code UPDATE Syntax Reviewed Common Transaction Mistakes Using an UPDATE to Minimize Transactional Code Real World Changes for Better Performance

UPDATE Syntax Reviewed varchar(10) = (SELECT MIN(title_id) FROM dbo.titles WHERE type = 'business') UPDATE titles SET type = 'MinTest', = title_id --Min may have changed go varchar(10) UPDATE titles SET type = = title_id WHERE title_id = (SELECT MIN(title_id) FROM dbo.titles WHERE type = 'business')

Common Transaction Mistakes Worst Scenario (Data Integrity Problems) BEGIN TRAN SELECT data to analyze before update IF data is OK then UPDATE (data may have changed) Reselect data to return to client COMMIT TRAN Better Scenario (No Data Integrity Issues) BEGIN TRAN UPDATE data right away Reselect data and Verify UPDATE Return Data to client COMMIT TRAN

Updates to Minimize Code Best Case Scenario No Data Integrity Issues Best Performance BEGIN TRAN UPDATE data and assign variable for Verify Verify UPDATE Return Data to client COMMIT TRAN Sometimes you can even get rid of the BEGIN TRAN and COMMIT TRAN!

Real World Changes BEGIN TRAN EXEC sp_executesql N'UPDATE dbo.table with (ROWLOCK, UPDLOCK) SET Col1 = Col1 WHERE Type SELECT Col1 FROM dbo.table WHERE Type int', COMMIT TRAN -- Was changed to: EXEC sp_executesql N'UPDATE dbo.table WITH (ROWLOCK, UPDLOCK) = Col1 = Col1 WHERE Type int‘, -- But sp_executesql is not necessary... UPDATE dbo.table = Col1 = Col1 WHERE Type

VLDB Backup Best Practices File/Filegroup Backup Strategies Case Study/Self Paced Example Gathering Backup History

File/Filegroup Backup Strategies Require Transaction Log backups for Restore Require FULL and/or Bulk Logged Recovery Model Do NOT Require a FULL Backup to have been performed – ever! Can BACKUP Files individually – not restricted to backup all files in a Filegroup (this was a change from SQL Server 7.0) Add Improved Restore Capabilities (less time) at the expense of some Administrative Complexity

Case Study Primary File1 File2 File3 Log time TLOGTLOG TLOGTLOG TLOGTLOG TLOGTLOG TLOGTLOG TLOGTLOG X FILEFILE FILEFILE FILEGROUPFILEGROUP DIFFFGDIFFFG DIFFFGDIFFFG Step 1 – Determine how to get the structure of the database created. Tip – need the Primary and all other FULL file/filegroup backups. Backups 7 and 3. Step 2 – Bring the file/filegroups up to the minute as fast as possible. Tip – find the latest differentials. Backup 9. Step 3 – Apply the Transaction Logs that will make this database consistent. Tip – Look for the oldest FULL file/filegroup or differential and then check for the min LSN. Backups – 6?, 8, 10, and 11. DBCREATEDBCREATE filegroup Demo

Gathering Backup History From Devices – LOAD HEADERONLY From MSDB, if the information exists SELECT Backup_Start_Date, [Name], [Description], First_LSN, Last_LSN, Backup_Finish_Date, * -- OR Just * FROM msdb.dbo.backupset AS s JOIN msdb.dbo.backupmediafamily AS m ON s.media_set_id = m.media_set_id WHERE database_name = 'PubsTest' ORDER BY 1 ASC Must find the Minimum Effective LSN * Take the oldest of the last few files or filegroups that have been restored and see what the FIRST_LSN is – that’s your minimum effective LSN. * Next find the FIRST log that includes this LSN.

Review Saving Production Data Case Sensitive Searching Creating Cool Constraints All About Raiserror Minimizing Transactional Code VLDB Backup Best Practices – File/Filegroup Backup/Restore

DAT 335 – SQL Server Tips and Tricks for DBAs and Developers Tuesday, 1 July 2003, 15:15-16:30 DBA 324 – Designing for Performance: Structures, Partitioning, Views and Constraints Wednesday, 2 July 2003, 08:30-09:45 DBA 328 – Designing for Performance: Optimization with Indexes Wednesday, 2 July 2003, 16:45-18:00 DBA 322 – Optimizing Stored Procedure Performance in SQL Server 2000 Thursday, 3 July 2003, 08:30-09:45 Other Sessions…

Articles in TSQLSolutions at (FREE, just register) All About Raiserror, InstantDoc ID#22980 Saving Production Data from Production DBAs, InstantDoc ID#22073 Articles in SQL Server Magazine, Sept 2002: Before Disaster Strikes, InstantDoc ID#25915 Log Backups Paused for Good Reason, InstantDoc ID#26032 Restoring After Isolated Disk Failure, InstantDoc #26067 Filegroup Usage for VLDBs, InstantDoc ID#26031 Search and for additional articleswww.sqlmag.comwww.tsqlsolutions.com Articles…

Inside Microsoft SQL Server 2000, Kalen Delaney, MS Press, ISBN: Whitepaper: Index Tuning Wizard for Microsoft SQL Server 2000, us/dnsql2k/html/itwforsql.asp?frame=true us/dnsql2k/html/itwforsql.asp?frame=true Whitepaper: Improving Performance with Microsoft SQL Server 2000 Indexed Views, us/dnsql2k/html/indexedviews1.asp?frame=true us/dnsql2k/html/indexedviews1.asp?frame=trueResources…

Community Resources Most Valuable Professional (MVP) Newsgroups Converse online with Microsoft Newsgroups, including Worldwide User Groups Meet and learn with your peers

Suggested Reading And Resources The tools you need to put technology to work! TITLE Available Microsoft® SQL Server™ 2000 High Availability: /9/03 Microsoft Press books are 20% off at the TechEd Bookstore Also buy any TWO Microsoft Press books and get a FREE T-Shirt

evaluations evaluations

Kimberly L. Tripp Principal Mentor, Solid Quality Learning Website: President, SYSolutions, Inc. Website: Thank You! Thank You!

© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.