ASP.NET Programming with C# and SQL Server First Edition

Slides:



Advertisements
Similar presentations
Chapter 7 Working with Databases and MySQL
Advertisements

Virtual training week 4 structured query language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition
Introduction to Structured Query Language (SQL)
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Concepts of Database Management Sixth Edition
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Microsoft Access Database software. What is a database? … a database is an organized collection of data. A collection of data of similar information compiled.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Database Lecture # 1 By Ubaid Ullah.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Concepts of Database Management Seventh Edition
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Introduction to SQL Steve Perry
Microsoft Access 2003 Define some key Access terminology: Field – A single characteristic or attribute of a person, place, object, event, or idea. Record.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Database: SQL and MySQL
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Concepts of Database Management Seventh Edition
Access Chapter 2: Relational Database Objectives Design data Create tables Understand table relationships Understand data types, key, & field properties.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Database and Information Management Chapter 9 – Computers: Understanding Technology, 3 rd edition.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
JDBC.
Chapter 7 Working with Databases and MySQL
Structured Query Language
Chapter 8 Working with Databases and MySQL
Presentation transcript:

ASP.NET Programming with C# and SQL Server First Edition Chapter 7 Working with Databases and SQL Server Express

Objectives In this chapter, you will: Study the basics of databases and SQL Server Work with SQL Server databases Define database tables Work with database records ASP.NET Programming with C# and SQL Server, First Edition

Introduction to Databases Database: an ordered collection of information from which a computer program can quickly access information Information in computer databases is stored in tables similar to spreadsheets Record: a single complete set of related information Field: an individual category of information stored in a record ASP.NET Programming with C# and SQL Server, First Edition

Introduction to Databases (cont’d.) Figure 7-1 Employee directory database ASP.NET Programming with C# and SQL Server, First Edition

Introduction to Databases (cont’d.) Flat-file database: stores information in a single table Useful for simple collections of information Relational database: stores information across multiple related tables Better for large and complex databases ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases Relational databases consist of one or more related tables Primary table: the main table in a relationship that is referenced by another table Related (or child) table: references a primary table in a relational database Tables in a relationship are connected using primary and foreign keys Primary and foreign keys link records across multiple tables ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) Primary key: a field that uniquely identifies a record in a table Foreign key: a field in a related table that refers to the primary key in a primary table Index: a field that identifies records in a database to make retrievals and sorting faster Primary key is a type of index Index may consist of one field or a combination of multiple fields ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) Three basic types of relationships in a relational database: One-to-one One-to-many Many-to-many One-to-one relationship: there is exactly one record in a related table for each record in the primary table Used to break information into multiple, logical sets Information in a one-to-one relationship could be placed within a single table ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) Figure 7-2 One-to-one relationship ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) One-to-many relationship: one record in a primary table has many related records in a related table Used to eliminate redundant information Only the primary and foreign keys are duplicated Normalization: the process of breaking tables into multiple related tables to reduce redundant and duplicate information Reduces the overall size of the database ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) Figure 7-3 Table with redundant information ASP.NET Programming with C# and SQL Server, First Edition

Figure 7-4 One-to-many relationship ASP.NET Programming with C# and SQL Server, First Edition

Understanding Relational Databases (cont’d.) Many-to-many relationship: many records in one table are related to many records in another table Junction table: creates a one-to-many relationship for each of the two tables in a many-to-many relationship Contains foreign keys from the two tables in the many-to-many relationship ASP.NET Programming with C# and SQL Server, First Edition

Figure 7-5 Many-to-many relationship ASP.NET Programming with C# and SQL Server, First Edition

Working with Database Management Systems Database management system (or DBMS): an application or collection of applications used to access and manage a database Schema: the structure of a database Includes its tables, fields, and relationships Flat-file database management system: stores data in a flat-file format Relational database management system (or RDBMS): stores data in a relational format ASP.NET Programming with C# and SQL Server, First Edition

Working with Database Management Systems (cont’d.) Popular commercial relational database managements systems include: Microsoft SQL Server Oracle Sybase Informix Microsoft Access Popular open source relational database management systems include: MySQL PostgresSQL ASP.NET Programming with C# and SQL Server, First Edition

Working with Database Management Systems (cont’d.) Functions of a DBMS: Creating new database files Allowing users to enter and manipulate data Structuring and preservation of the database file(s) Ensuring that data is stored correctly in tables Ensuring that relationships are enforced Providing authentication and authorization features Query: a structured set of instructions and criteria for retrieving, adding, modifying, and deleting database information ASP.NET Programming with C# and SQL Server, First Edition

Working with Database Management Systems (cont’d.) Data manipulation language (or DML): a language for creating queries Structured Query Language (or SQL): supported by most DBMSs for creating queries Most DBMSs provide an interface to design queries Must still learn SQL for programmatically accessing a database Each DBMS creates its own proprietary file types Most have the ability to import data from other file formats but cannot directly read each other’s files ASP.NET Programming with C# and SQL Server, First Edition

Querying Databases with Structured Query Language SQL has become an official standard for querying databases SQL statements are composed of keywords that perform actions on a database SELECT statement returns data from the database ASP.NET Programming with C# and SQL Server, First Edition

Querying Databases with Structured Query Language (cont’d.) Table 7-1 Common SQL keywords ASP.NET Programming with C# and SQL Server, First Edition

Getting Started with SQL Server Microsoft SQL Server Management Studio Express: a graphic tool for manipulating SQL Server databases New Query window: used to execute SQL commands SQL Server Query Designer: a graphic tool for creating queries in a graphical environment Can drag fields from table objects or can center SQL commands directly ASP.NET Programming with C# and SQL Server, First Edition

Getting Started with SQL Server (cont’d.) Figure 7-6 Microsoft SQL Server Management Studio Express ASP.NET Programming with C# and SQL Server, First Edition

Getting Started with SQL Server (cont’d.) Figure 7-7 Query window in SQL Server Management Studio Express ASP.NET Programming with C# and SQL Server, First Edition

Getting Started with SQL Server (cont’d.) Figure 7-8 Query Designer in SQL Server Management Studio Express ASP.NET Programming with C# and SQL Server, First Edition

Installing SQL Server 2008 Management Studio Express To install SQL Server Management Studio Express: Download the installation package from Microsoft’s Web site Start the installation package that you downloaded Select Installation link Select New SQL Server stand-alone installation or add features to an existing installation link Follow the rest of the on-screen instructions to complete the installation ASP.NET Programming with C# and SQL Server, First Edition

Working with the SQL Server Management Studio Express Query window allows you to enter SQL commands Does not have a graphical interface SQL commands must be terminated with a semicolon If no semicolon, the query window assumes you want to enter more SQL statements From the Query menu, select Execute to execute the SQL commands in the query window Results window displays the results of executing the SQL commands ASP.NET Programming with C# and SQL Server, First Edition

Figure 7-9 Results window showing results of a SQL query ASP.NET Programming with C# and SQL Server, First Edition

Working with the SQL Server Management Studio Express (cont’d.) Figure 7-10 Output from a multiline SQL command ASP.NET Programming with C# and SQL Server, First Edition

Understanding SQL Server Identifiers You must define identifiers (names) for databases, tables, fields, and indexes Two types of identifiers: Regular identifiers: must begin with a letter, underscore (_), number sign (#) or at sign (@) Delimited identifiers: enclosed by double quotations (“”) or brackets ([]), and may contain spaces or other characters not allowed in regular identifiers ASP.NET Programming with C# and SQL Server, First Edition

Understanding SQL Server Identifiers (cont’d.) To use SQL Server Management Studio Express, you must connect to a server Instance: refers to a single SQL Server database An installation of SQL Server can have many instances Default instance is named SQLEXPRESS Authentication types: Windows Authentication SQL Server Authentication ASP.NET Programming with C# and SQL Server, First Edition

Understanding SQL Server Identifiers (cont’d.) Figure 7-11 Connect to Server dialog box ASP.NET Programming with C# and SQL Server, First Edition

Working with SQL Server Databases The basics of working with databases in SQL Server include: Creating databases Deleting databases Specifying field data types Creating tables Deleting tables ASP.NET Programming with C# and SQL Server, First Edition

Creating Databases Use the CREATE DATABASE statement to create a new database Syntax: CREATE DATABASE databaseName; databaseName must be unique New databases are created with a file extension of .mds Can specify the location for the database using the FILENAME keyword Must define tables and fields after creating the database ASP.NET Programming with C# and SQL Server, First Edition

Deleting Databases Use the DROP DATABASE statement to delete a database This removes all tables from the database and deletes the database itself Syntax: DROP DATABASE databaseName; ASP.NET Programming with C# and SQL Server, First Edition

Specifying Field Data Types Fields in a database store data according to type Data type determines the amount of memory and storage space required for the field SQL Server includes numeric, string, monetary, and date/time data types Choose the smallest data type possible for each field ASP.NET Programming with C# and SQL Server, First Edition

Table 7-2 Common SQL Server data types ASP.NET Programming with C# and SQL Server, First Edition

Creating Tables Use the CREATE TABLE statement to specify the table, the column names, and the data type for each column Syntax: CREATE TABLE tableName (columnName Type, …); Column names must be unique within a table Table names must be unique with the database Must select the database with the USE database statement first to use it in a query window ASP.NET Programming with C# and SQL Server, First Edition

Deleting Tables Use the DROP TABLE statement to remove all data from a table and delete the table definition Syntax: DROP TABLE tableName; ASP.NET Programming with C# and SQL Server, First Edition

Working with Records Working with records includes: Adding records to a table Modifying existing records in a table Deleting existing records in a table ASP.NET Programming with C# and SQL Server, First Edition

Adding Records Use the INSERT statement to add a single new record to a table Syntax: INSERT INTO tableName VALUES (value1,value2,…); Text values are enclosed within single quotations Values in the VALUES list must be in the same order in which the fields are defined in the table Specify NULL in any fields for which you do not have a value ASP.NET Programming with C# and SQL Server, First Edition

Adding Records (cont’d.) Use the BULK INSERT statement with a local text file to add multiple records to an existing database Syntax: BULK INSERT tableName FROM ‘filePath’; Each record in the text file should be on a separate line with tabs between each field Leave empty fields blank Values on each line must be in the same order as the fields are defined in the table ASP.NET Programming with C# and SQL Server, First Edition

Adding Records (cont’d.) Figure 7-12 Results window after adding records to the outlook table in the forecast database ASP.NET Programming with C# and SQL Server, First Edition

Retrieving Records Use a SELECT statement to retrieve records from a table Syntax: SELECT criteria FROM tableName; Use * to select all fields, or list individual field names separated by commas ASP.NET Programming with C# and SQL Server, First Edition

Retrieving Records (cont’d.) Figure 7-13 Individual fields returned with a SELECT statement ASP.NET Programming with C# and SQL Server, First Edition

Sorting Query Results Use the ORDER BY keyword with the SELECT statement to sort results alphanumerically Syntax: SELECT criteria FROM tableName ORDER BY fieldName; Add the DESC keyword to sort in reverse (in descending order) ASP.NET Programming with C# and SQL Server, First Edition

Sorting Query Results (cont’d.) Figure 7-14 Results returned from inventory table of the skateboards database sorted by price ASP.NET Programming with C# and SQL Server, First Edition

Sorting Query Results (cont’d.) Figure 7-15 Results returned from inventory table of the skateboards database reverse sorted by price ASP.NET Programming with C# and SQL Server, First Edition

Filtering Query Results Use the criteria portion of the SELECT statement to determine which fields to retrieve from a table Use the WHERE keyword to specify which records to return Syntax: SELECT criteria FROM tableName WHERE condition; Can use AND and OR keywords to specify more detailed conditions in the WHERE clause ASP.NET Programming with C# and SQL Server, First Edition

Filtering Query Results (cont’d.) Figure 7-16 Results returned from the inventory table of the skateboards database where price is less than 100 ASP.NET Programming with C# and SQL Server, First Edition

Filtering Query Results (cont’d.) Figure 7-17 Results returned from the inventory table of the skateboards database where price is greater than 100 and length is less than 30 ASP.NET Programming with C# and SQL Server, First Edition

Filtering Query Results (cont’d.) Figure 7-18 Results returned from the inventory table of the skateboards database where price is greater than 100 or length is less than 30 ASP.NET Programming with C# and SQL Server, First Edition

Updating Records Use the UPDATE statement to update existing records in a table Syntax: UPDATE tableName SET columnName=value WHERE condition; Must use a WHERE condition to specify which record to update ASP.NET Programming with C# and SQL Server, First Edition

Deleting Records Use the DELETE statement to delete existing records in a table Syntax: DELETE FROM tableName WHERE condition; Must use the WHERE clause to specify which record(s) to delete ASP.NET Programming with C# and SQL Server, First Edition

Summary A database is an ordered collection of information from which a computer program can quickly access information A record is a single complete set of related information Fields are individual categories of information stored in a record Flat-file database stores information in a single table Relational database stores information across multiple tables ASP.NET Programming with C# and SQL Server, First Edition

Summary (cont’d.)‏ A query is a structured set of instructions and criteria for retrieving, adding, modifying, and deleting database information Structured Query Language (SQL) has become a standard data manipulation language for many database management systems Microsoft SQL Server Management Studio Express is a graphic tool for manipulating a SQL Server database Regular identifiers begin with a letter, underscore, number sign, or at sign ASP.NET Programming with C# and SQL Server, First Edition

Summary (cont’d.)‏ Delimited identifiers allow spaces and other characters, enclosed within double quotations or brackets Use the USE statement to select a database to work with Use the CREATE DATABASE statement to create a new database Use the DROP DATABASE statement to delete a database Choose the smallest data type possible for each field in a table ASP.NET Programming with C# and SQL Server, First Edition

Summary (cont’d.)‏ Use the CREATE TABLE statement to create a new table and specify the column names and data types Use the DROP TABLE statement to delete a table Use the INSERT statement to add a single record to a table Use the BULK INSERT statement to add multiple records to a table from a local text file Use the SELECT statement to retrieve records from a table ASP.NET Programming with C# and SQL Server, First Edition

Summary (cont’d.)‏ Use the ORDER BY keyword in a SELECT statement to sort the results returned by a query Use the WHERE keyword to specify which records to return from a database Use the UPDATE statement to update records in a table Use the DELETE statement to delete records in a table ASP.NET Programming with C# and SQL Server, First Edition