Database Fundamentals

Slides:



Advertisements
Similar presentations
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Advertisements

Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Meet Jeremy Thake Jeremy recently joined Microsoft as Technical Product Manager for the Visual Studio Developer story for Office 365 development.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
04 | Customize Team Foundation Server for Team Use Anthony Borton | ALM Consultant, Enhance ALM Steven Borg | Co-founder & Strategist, Northwest Cadence.
02 | Advanced SELECT Statements Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Gerry O’Brien| Technical Content Development Manager Paul Pardi| Senior Content Publishing Manager.
Bill Baer is a Senior Product Marketing Manager and Microsoft Certified Master for SharePoint in the SharePoint product group in Redmond, Washington;
Module 2 Working with Data Types. Module Overview Using Data Types Working with Character Data Converting Data Types Working with Specialized Data Types.
Overview of SQL Server Alka Arora.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Course Topics Administering SQL Server 2012 Jump Start 01 | Install and Configure SQL Server04 | Manage Data 02 | Maintain Instances and Databases05 |
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Module 1: Introduction to Transact-SQL
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
Feature: Suggested Item Enhancements – Sales Script and Additional Information © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
10 | Programming with Transact-SQL Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Data Types Lesson 4. Skills Matrix Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each.
customer.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
02 | Core Programming Gerry O’Brien | Technical Content Development Manager Paul Pardi | Senior Content Publishing Manager.
03 | Word Templates Brian Meier| Senior Lead Program Manager.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
demo Demo.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
03 | Object-Oriented Programming Gerry O’Brien | Technical Content Development Manager Paul Pardi | Senior Content Publishing Manager.
04 | Business Analyzer Brian Meier| Senior Lead Program Manager.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Module 9: Using Advanced Techniques. Considerations for Querying Data Working with Data Types Cursors and Set-Based Queries Dynamic SQL Maintaining Query.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
SQL Triggers, Functions & Stored Procedures Programming Operations.
What is your Character Data Type? March 5, 2016 John Deardurff Website:
Advanced SQL - DDL Advanced Database Dr. AlaaEddin Almabhouh.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
John Tran Business Program Manager, The Suddath Companies
Querying with Transact-SQL
Creating Database Objects
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Module 2: Creating Data Types and Tables
2010 Microsoft BI Conference
Data Definition and Data Types
Attributes and Domains
Ouch! Our Data Type Choices Did THAT?
Microsoft Dynamics NAV 2017
Entity Based Staging SQL Server 2012 Tyler Graham
Proper DataType Usage = Guaranteed Better Performance and Accuracy
ISC440: Web Programming 2 Server-side Scripting PHP 3
What is your Character Data Type?
Working with Data Types
Microsoft SQL Server 2014 for Oracle DBAs Module 7
PT2520 Unit 5: Physical Design
Sunil Agarwal | Principal Program Manager
Attributes and Domains
Creating Database Objects
Presentation transcript:

Database Fundamentals Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher

Meet Brian Alderman | ‏@brianalderman Chief Executive Office, Founder MicroTechPoint Industry-recognized consultant Noted author and conference speaker Brian’s expertise and designs range across Microsoft operating systems More than 25 years of industry experience Brian has been focused on helping IT Pros and Database Administrators (DBAs) better understand core Microsoft technologies for over 25 years. A frequent presenter at SharePoint Conferences around the world, he has authored or contributed to several SharePoint, SQL Server, and other technical books, and is a MCSE, MCT, and MCITP: SharePoint and SQL Server Administrator. Brian has a BS and MS in Computer Information Systems where he graduated summa cum laude from Regis University of Colorado Springs and lives in Scottsdale, AZ where he enjoys playing golf year round and traveling around the world. LinkedIn /brianalderman Blog http://brianalderman.wordpress.com

Meet Pete Harris | @SQLPete Content Development Manager in Microsoft’s Learning Experiences team Focuses on SQL Server and Web training  With Microsoft since 1995  Part of the first team of developer training folks in the post-Microsoft University era Has built a variety of content and spoken to customers all over the world

Course Modules Database Fundamentals 01 | Introducing core database concepts (50 minutes) Define databases, example of relational database tables, and introduce common database terminology 02 | Relational Concepts (50 minutes) Normalization, referential integrity, and constraints 03 | Creating databases and database objects (50 minutes) Data types, database objects, DDL statements, and creating scripts 04 | Using DML statements (50 minutes) DML statements, using the SELECT statement; using INSERT, UPDATE, and DELETE to manage data; indexes and triggers 05 | SQL Server Administration Fundamentals (50 minutes) SQL Server security; securing database and objects; performing database backups and database restores

03 | Creating Databases and Database Objects Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher

Module Overview Data types Database objects DDL statements

Data types

Data types A data type is an attribute that specifies the type of data that an object can hold as well as the number of bytes of information that can be stored in the object If you have similar data types to choose from but they only differ in byte size, use the data type that has a larger range of values and/or has increased precision Exact numeric data types (int, tinyint) are the most common SQL Server data types used to store numeric information. Approximate Numerics include precision (p) which is the total number of decimal digits that could be stored, both to the left and right of the decimal point.

Data types Unicode data types provide storage of international characters, such as Japanese and Chinese, to allow worldwide businesses to use big vendor database products to store their data. Unicode data types takes more bytes to store the data in the database If you have similar data types to choose from but they only differ in byte size, use the data type that has a larger range of values and/or has increased precision Exact numeric data types (int, tinyint) are the most common SQL Server data types used to store numeric information. Approximate Numerics include precision (p) which is the total number of decimal digits that could be stored, both to the left and right of the decimal point.

Built-in data type categories SQL Server 2012’s built-in data types are organized into the following categories: Exact numerics – (bigint, bit, decimal, int, money, numeric, smallint) Approximate numerics (float, real) Date and time (date, datetime2, datetime, datetimeoffset, time) Character strings (char, varchar, text) Unicode character strings (nchar, ntext, nvarchar) Binary strings (binary, varbinary, image) Other data types (cursor, timestamp, uniqueidentifier, table) Large valued data types (varchar(max), nvarchar(max)) Large object data types (text, ntext, image, xml)

Data types Money - used where you’ll store money or currency values Int - used to store whole numbers and when performing mathematical computations Float - commonly used in the scientific community and is considered an approximate-number data type Datetime - used to store date and time values in one of many different formats

Data types Char – fixed length non-unicode string data type where n defines the string length Varchar – variable length non-unicode string data type that indicates the actual storage size of the data Bit (Boolean) – integer that can have a null, 0 (False), or 1 (True) value Datetimeoffset – a date combined with time of day that has time zone awareness

Data types storage size Use/Description Storage Size Money Monetary or currency values -922,337,203,685,477.5808 to 922,337,203,685,477.5807 8 bytes Int Integer data from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 4 bytes Float Approximate number - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308 Depends on the value of n Datetime Date Range January 1, 1753, through December 31, 9999 Time Range 00:00:00 through 23:59:59.997 Char Fixed-length, non-Unicode string data. Can be a value from 1 through 8,000 n bytes Varchar Variable-length non-Unicode string. Can be a value from 1 through 8,000 Actual length + 2 bytes Bit Integer with a value of 0 or 1. 1 byte for every 8 bit columns Datetimeoffset Date range January 1,1 A.D. through December 31, 9999 A.D. Time range 00:00:00 through 23:59:59.9999999 Time zone offset range -14:00 through +14:00 10 Bytes

Implicit and explicit conversions Implicit data type conversions occurs when the SQL Server expression evaluator automatically converts data from one data type to another to complete an operation like a comparison of two values Explicit data type conversions require the use of the CONVERT or CAST function to convert data from one data type to another before an operation like a comparison can be completed. To convert a numeric value into a character string CAST ( $157.27 AS VARCHAR(10) ) Not all data types conversions are supported nchar cannot be converted to image Use CAST instead of CONVERT to adhere to ISO Use CONVERT instead of CAST to take advantage of the style functionality

Database objects

Tables A table is a collection of rows and columns that is used to organize information about a single topic. Each row within a table corresponds to a single record and contains several attributes that describe the row. EmployeeID LastName FirstName Department 100 Smith Bob IT 101 Jones Susan Marketing 102 Adams John Finance

Views A view is simply a virtual table consisting of different columns from one or more tables. Unlike a table, a view is stored in the database as a query object; therefore, a view is an object that obtains its data from one or more underlying tables.

Stored procedures A stored procedure is a group of Transact-SQL statements that have been compiled and saved so it can be run several times. Parameters can be passed to and returned from a stored procedure so they can be reused with different values. IF (@QuantityOrdered < (SELECT QuantityOnHand FROM Inventory WHERE PartID = @PartOrdered) ) BEGIN -- SQL statements to update tables and process order. END ELSE -- SELECT statement to retrieve the IDs of alternate items -- to suggest as replacements to the customer.

User-Defined functions User-defined functions (udf) are routines that takes zero or more parameters, completes an operation, and return the result of the operation as a value. There are three types of functions Scalar – returns a single data value Table-valued – returns a table data type System – Provided by SQL Server, cannot be modified

Primary differences between stored procedures and user-defined functions Stored Procedures Called independently using EXEC statement Cannot JOIN stored procedures Can be used to modify SQL Server configuration Can use nondeterministic functions such as GETDATE() User-defined Functions Called from within another SQL statement Can JOIN UDF’s Cannot be used to modify SQL Server configuration Always stops execution of T-SQL code if error occurs

Naming conventions for your objects PascalCase - The first letter of the identifier and the first letter of each subsequent concatenated word is capitalized EmployeeTable camelCase - The first letter of the identifier is lowercase and the first letter of each subsequent concatenated word is capitalized employeeTable Tip: Pick a naming convention and use it consistently throughout your database environment

Create a ClassDemoDB Database

DDL Statements

Common DDL statements CREATE – define new entities ALTER – modify existing entities DROP – remove existing entities

CREATE statement Used to create new entities in SQL Server including some of the most common entities Database Procedure Table Trigger Default View Index User Login Role CREATE DATABASE Sales ON ( NAME = Sales_dat, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\sales.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\salelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB ) ;

Create new table USE SALES GO --Create new table called Products CREATE TABLE dbo.Products1 ( ProductID int NULL, ProductName varchar(20) NULL, UnitPrice money NULL, ProductDescription varchar(50) NULL );

ALTER statement Used to modify existing entities in SQL Server including Database Trigger Table View Index User Login Role Procedure Schema ALTER DATABASE Sales Modify Name = SalesForecast ;

DROP statement Used to delete existing entities in SQL Server including Database Trigger Table View Index User Login Role Procedure Schema DROP DATABASE SalesForecast

Creating SQL Server Objects and generating scripts Demo Creating SQL Server Objects and generating scripts

Summary A data type is an attribute that specifies the type of data that an object can hold The built-in data types fall into the following categories: Exact numerics Approximate numerics Date and time Character strings Unicode character strings Binary strings Other data types Large valued data types Large object data types

Summary A database can be created using SSMS or using the T-SQL CREATE DATABASE statement Database objects such as tables, views, stored procedures, and user-defined functions can be created using SSMS or using a DDL CREATE statement Database objects should be consistently created using either the PascalCase or camelCase naming convention

Summary The purpose of a table is to provide structure for storing data within a relational database A view is a virtual table consisting of columns from one or more tables and is stored in the database as a query object A stored procedure is a group of Transact-SQL statements that have been compiled and saved so they can be run several times Scripts can be created from existing objects