© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.

Slides:



Advertisements
Similar presentations
1 After completing this lesson, you will be able to: Create a database. Create a table using the Table Wizard. Create and modify a table in Design view.
Advertisements

Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Microsoft Excel 2003 Illustrated Complete Excel Files and Incorporating Web Information Sharing.
Exploring Microsoft Excel 2002 Chapter 7 Chapter 7 List and Data Management: Converting Data to Information By Robert T. Grauer Maryann Barber Exploring.
Introduction to Structured Query Language (SQL)
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
John Cooney Research Systems Project, Training and Web Manager Monash Research Office Research Information Systems How to obtain your DIISR points via.
Introduction to Structured Query Language (SQL)
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.
Concepts of Database Management Sixth Edition
 Pages made using data in a database  Use scripting languages  Use of RDMS  Look and feel by templates, CSS  High scaling  Admin pages as back end.
Microsoft Access 2007 Microsoft Access 2007 Introduction to Database Programs.
1 Working with MS SQL Server II. 2 The sqlcmd Utility Command line utility for MS SQL Server databases. Previous version called osql Available on classroom.
1 Working with MS SQL Server. 2 Objectives You will be able to Use Visual Studio for GUI based interactive access to a Microsoft SQL Server database.
CSCI 6962: Server-side Design and Programming
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Introduction to Access By Mary Ann Chaney and Alicia Harkleroad.
Databases and LINQ Visual Basic 2010 How to Program 1.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 4 – Creating New.
ASP.NET Programming with C# and SQL Server First Edition
Exploring Office 2003 Vol 1 2/e - Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1- Introduction to Access: What is.
1 Lesson 22 Getting Started with Access Essentials Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chapter 15: Using LINQ to Access Data in C# Programs.
Microsoft Access Get a green book. Page AC 2 Define Access Define database.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
1 Working with MS SQL Server Textbook Chapter 14.
Lesson 17 Getting Started with Access Essentials
Relational Databases (MS Access)
Microsoft Access You will need a pen/pencil.. What is Microsoft Access? Access is a database management system.  Create a database, add/change delete.
Key Applications Module Lesson 21 — Access Essentials
Concepts of Database Management Seventh Edition
Chapter 17 Creating a Database.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
McGraw-Hill/Irwin The O’Leary Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lab 6 Creating and Using Lists and.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Microsoft Access. Microsoft access is a database programs that allows you to store retrieve, analyze and print information. Companies use databases for.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Lesson 01: Introduction to Database Software. At the end of this lesson, students should be able to: State the usage of database software. Start a database.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Database Objective Demonstrate basic database concepts and functions.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Planning & Creating a Database By Ms. Naira Microsoft Access.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
INTRODUCTION TO DATABASES USING MICROSOFT ACCESS Basic Database Terms Create A Database Creating Table Fields Populating a Table Modifying Data Create.
Ennis-Cole, AC 2.01, CECS Maintaining A Database By: Dr. Ennis-Cole.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
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.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
Chapter 28. Copyright 2003, Paradigm Publishing Inc. CHAPTER 28 BACKNEXTEND 28-2 LINKS TO OBJECTIVES Table Calculations Table Properties Fields in a Table.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
COMPUTER SKILLS MS-ACCESS. Introduction Access is a piece of software known as a database management system. At its most basic level, it can be used to.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
3 A Guide to MySQL.
Visual Basic 2010 How to Program
Practical Office 2007 Chapter 10
Data Definition and Data Types
Database application MySQL Database and PhpMyAdmin
Database Fundamentals
Presentation transcript:

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Ä Duration: Ä Purpose: Ä Audience: Ä Test: Introduction

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 3 Objectives You will be able to  Use Visual Studio for GUI based interactive access to a Microsoft SQL Server database. Populate a table with data from an Excel worksheet.  Use sqlcmd for command line interactive access to a Microsoft SQL Server database.  Using either Visual Studio or sqlcmd Create and delete tables. Modify table definitions. Insert new rows into tables. Modify existing rows. Retrieve and display table data.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 4 Using Visual Studio 2008  Visual Studio 2008 includes database access functions.  View "Server Explorer"  Set up a Data Connection

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 5 Data Connections in Visual Studio 2008 Right click on Data Connections and select Add Connection.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 6 Adding a Data Connection

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 7 Adding a Data Connection Your SQL Server Username Your SQL Server Password

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 8 Test the Connection Click here

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 9 Adding a Table  We will create a new table to hold the addresses in file Addresses.csv.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 10 Adding a Table

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 11 Adding a Table

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 12 Data Types  Common SQL Data Types int nvarchar(n)n = max number chars char(n)n = number chars decimal (p,s)p = total number of digits s = number decimal places datetime  Many more!

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 13 Setting an ID Field  It is good practice to include an ID field for every row. Unique identifier  Not present in the Excel worksheet.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 14 Setting an ID Field We will designate this as the “Primary ID”

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 15 Setting the Primary Key Right Click here System ensures that the Primary Key is unique.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 16 Define Other Columns

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 17 Save the Table Definition Save

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 18 Table "Addresses" is Now Present

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 19 Viewing Table Data Right click on Addresses and select “Show Table Data”.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 20 Viewing Table Data Table is currently empty.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 21 Populating a Table  Download file Addresses.csv from the Downloads area of the class web site:  Downloads/Addresses.csv Downloads/Addresses.csv  Double click to open in Excel

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 22 Excel Worksheet

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 23 Add ID Field  In order to use this data in the database table we need to add an ID field.  In Excel (2007), right click on the column header “A” and select “insert” in the dropdown menu. Adds a new column.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 24 Adding an ID Column

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 25 Setting ID Values  Set the ID for the first row to 1.  Select ID on second row Press = Click the cell above (ID of the first row) Click in the formula window and add “+1” Formula window should now say =A1+1

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 26 Setting ID Values Press Enter

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 27 Setting ID Values

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 28 Setting ID Values  Copy the formula in 2A down into all the cells below it.  Click on 2A  Shift click on 175A  Press Ctrl-d (to copy Down)  Should now see consecutive numbers 1 – 175 in the first column

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 29 Addresses with IDs

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 30 Populating the Database Table  We will use the contents of this Excel worksheet to populate the Address table in the database.  Click inside the worksheet, then press Ctrl-A to select all.  Press Ctrl-C to copy the entire worksheet to the clipboard.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 31 Populating the Database Table Click here to select all of the table. Press Ctrl-V to paste the clipboard into the table. (This may take a while to complete.)

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 32 The Table is Populated

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 33 The sqlcmd Utility  Command line utility for MS SQL Server databases. Previous version called osql  Available on classroom and lab PCs.  In Windows command window Connect to a Database Server Enter SQL commands on the command line. Results output to the console.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 34 Getting and Installing sqlcmd  Included with Management Studio Express.  Free download from Microsoft,  Documentation available in SQL Server 2005 Books Online Free download from Microsoft.  In Visual Studio 2008, search for sqlcmd.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 35 The SQL Language  The following slides demonstrate SQL commands using the sqlcmd program.  Remember SQL is used everywhere we interact with a database server: Command line Database management programs Our own programs

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 36 Using sqlcmd The Server My Username Password entered here Execute commands in buffer

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 37 SQL Command Line Example  View a subset of the columns.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 38 Retrieve Specific Entries Find all addresses with zip code 33707

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 39 Wildcard Selection Find all addresses with last name beginning with S

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 40 Wildcard Selection All addresses with last name containing an s

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 41 Case Sensitivity  Typically SQL commands and keywords are not case sensitive.  Data is case sensitive Characters are stored as upper case or lower case.  Sorting order is a mode Default is not case sensitive Search comparisons same as sorting order.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 42 Case Sensitivity

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 43 Sorting the Output Zip_Code is a string. So sort is lexicographic, not numeric.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 44 Counting Rows How many addresses are there with zip code 33707?

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 45 Updating Records

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 46 Updating Records

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 47 Updating Multiple Fields

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 48 Deleting a Record

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 49 SQL Commands in Visual Studio  We can also use Visual Studio to issue arbitrary SQL commands to the server.  On the Data menu select New Query

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 50 SQL Commands in Visual Studio

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 51 SQL Commands in Visual Studio Click here

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 52 SQL Commands in Visual Studio Enter SQL command here.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 53 SQL Commands in Visual Studio Click here to execute the command.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 54 SQL Commands in Visual Studio Results appear below the Query window.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 55 Learning SQL  Many books available  One that I recommend: Teach Yourself SQL in 24 Hours (Third Edition) Ryan Stephens and Ron Plew, SAMS, 2003  Lots of information on the web  A sampling: