Learningcomputer.com SQL Server 2008 – Introduction to Transact SQL.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Virtual training week 4 structured query language (SQL)
Introduction to Structured Query Language (SQL)
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
Chapter 04 How to retrieve data in a single table MIT 22033, Database Management System By: S. Sabraz Nawaz.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Introduction.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Nichelle K. Norris IS 373: World Wide Web Standards.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Introduction to SQL Steve Perry
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Said Salomon Unitrin Direct Insurance T-SQL for Beginners Said Salomon CODE CAMP
Today’s Topics Backup Recap Restoration and Recovery T-SQL Commands –INSERT –UPDATE –DELETE –BEGIN TRAN –COMMIT TRAN –ROLLBACK TRAN.
Upgrading to SQL Server 2000 Kashef Mughal. Multiple Versions SQL Server 2000 supports multiple versions of SQL Server on the same machine It does that.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
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.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
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.
SQL Triggers, Functions & Stored Procedures Programming Operations.
SQL Basics Review Reviewing what we’ve learned so far…….
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.
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
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.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Advanced Accounting Information Systems
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to Structured Query Language(SQL)
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Introduction to Web programming
Introduction to Oracle9i: SQL
ISC440: Web Programming 2 Server-side Scripting PHP 3
SQL 101.
Introduction To Structured Query Language (SQL)
SQL Queries Chapter No 3.
HAVING,INDEX,COMMIT & ROLLBACK
SQL .. An overview lecture3.
Introduction To Structured Query Language (SQL)
Structured Query Language
Introduction to Web programming
Presentation transcript:

Learningcomputer.com SQL Server 2008 – Introduction to Transact SQL

What is Transact SQL? It is pronounced as Transact SQL or Transact SEQUEL Transact SQL or TSQL is a powerful database language It provides programmatic functionality within the relational databases provided by Microsoft SQL SERVER and Sybase database products It is SQL-92 compliant as set by ANSI (American National Standards Institute) It can be broken down into two main areas DML (Data manipulation language) e.g. SELECT, INSERT.. DDL (Data definition language) e.g. CREATE TABLE, DROP DATABASE..

Sample database AdventureWorks2008 Adventure Works Cycles, the fictitious company on which the database is based on. It primarily sells bicycle and parts The downloads can be found here ectReleases.aspx?ReleaseId= ectReleases.aspx?ReleaseId=16040 I had some issues running the download program and had to run this command from C:\ regsvr32 vbscript.dll After the download, I was able to run this script RestoreAdventureWorks2008.sql. This was found here C:\Program Files\Microsoft SQL Server\100\Tools\Samples – I had to replace value variable to bolded text above

DML statements for today SELECT INSERT UPDATE DELETE

Mighty SELECT statement The SELECT statement forms the core of the SQL database language Most commonly used SQL command by far You use the SELECT statement to select or retrieve rows and columns from database tables It does not make any changes to the underlying data This statement can use a sub-select (sub query) The SELECT statement syntax contains five major clauses, generally constructed as follows

SELECT statement syntax SELECT FROM [WHERE ] [GROUP BY ] [HAVING ] [ORDER BY ]; * Notice the bold code is required

SELECT Example We will be using the Adventureorks2008 sample database for SQL Server Launch SQL Server Management Studio and connect to your local SQL instance Expand the database tab and select Adventureorks2008 Right click and select New Query Type the following SELECT * FROM PERSON.PERSON WHERE LASTNAME='WOOD‘ It should return 87 rows also known as records

A little more on SELECT Lets try SalesOrderHeader table with multiple condition SELECT * FROM SALES.SALESORDERHEADER WHERE TERRITORYID=1 AND ORDERDATE < ' ' Quick way to copy data from one table to another is SELECT INTO. Why would you need this? SELECT * INTO HUMANRESOURCES.EMPLOYEE2 FROM HUMANRESOURCES.EMPLOYEE

SQL Operators Operators are used to limit the number of results from the query. Also they are used for mathematical and logical operations. Here are a few types of operators. Standard Operators: = equal to <>not equal to greater than >= greater than or equal to between used to show between two numbers Logical Operators AND used when both conditions are included OR used when either of the condition is true NOT opposite of the logical value

INSERT statement Inserts one or more new rows into the specified table When you use the VALUES clause, only a single row is inserted. Typically used to insert single row of data. However INSERT can use a sub-select (sub query) to insert multiple records.

INSERT Syntax INSERT INTO table-name [({column-name},...)] VALUES ({literal},...) | select-statement} If you use a sub-select statement, the number of rows inserted equals the number of rows returned by the select statement Makes it easier to manage the permissions in your databases

INSERT Example We will be using the Person.Person table For BusinessEntityID, I had to insert a record into BusinessEntity for referential integrity, more on this later Right click and select New Query Type the following INSERT INTO PERSON.PERSON (BUSINESSENTITYID, PERSONTYPE, NAMESTYLE,FIRSTNAME, LASTNAME, PROMOTION, MODIFIEDDATE) VALUES (20778, 'EM', 0, 'KASH', 'MUGHAL', 0, GETDATE()) This should insert one record into Person table

UPDATE statement This is used to update data in the tables Uses a WHERE clause to seek the rows that need to be updated Can use a sub-select (sub query) to update data from another underlying table In the absence of WHERE clause, all the records are updated Be VERY careful with this one!

UPDATE Syntax In its simplest form, here is the syntax UPDATE tablename SET {column-name = { | NULL}},... [WHERE ] Notice the Where clause is optional (enclosed in []) however I would strongly recommend using it regularly If you use a sub-select statement, the number of rows inserted equals the number of rows returned by the select statement

UPDATE Example We will update the record that we just inserted into Person.Person table Right click and select new query Type the following UPDATE Person.Person SET FirstName='KASHEF' WHERE BusinessEntityID=20778 This will update one record only

And my favorite DELETE statement Used to delete data from tables Like the Update statement uses the WHERE clause to locate the records to delete. In case of No WHERE clause, deletes all the records in the table Be very careful with this one also! Remember there is no Undo or Control + Z in SQL Server!! Funny but TRUE story

DELETE Syntax DELETE FROM {table-name } [WHERE ]; Notice how you do not need * in fact it will give you an error Where clause is optional (enclosed in []) however I would strongly recommend using it regularly Delete statement can use a sub-select (sub query) In the absence of where clause deletes all rows, enough said

DELETE Example Expand the database tab and select AdventureWorks2008 We will delete one row from Person table, the one we inserted earlier Right click and select new query Type the following DELETE FROM PERSON.PERSON WHERE BUSINESSENTITYID=20778

Review SELECT INSERT UPDATE DELETE