Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured Query Language SQL IST359 M005 Yang Wang 342 Hinds

Similar presentations


Presentation on theme: "Structured Query Language SQL IST359 M005 Yang Wang 342 Hinds"— Presentation transcript:

1 Structured Query Language SQL IST359 M005 Yang Wang ywang@syr.edu 342 Hinds http://blackboard.syr.edu

2 Acknowledgements and caveat These slides draw liberally, with permission, from the following sources: IST359 materials by Prof. Michael Fudge Jr. Slides from Murach’s SQL Server 2008 book Caveat (beware): At best, PowerPoint slides are only a pale limitation of the entirety of a class meeting. In IST359 in particular, the lectures will cover topics beyond what appears in these slides. Don’t rely on them as a substitute for attending class.

3 Learning Objectives Describe and use basic SQL commands Explain how and why SQL is used, and why it’s important Compare and contrast DML and DDL Use SQL commands to create metadata structures and perform CRUD operations.

4 WHAT IS SQL? A computer programming language designed for managing data and structures (metadata) in relational database management systems.

5 Brief History of SQL 1970– E. Codd develops relational database concept 1974-1979–System R with Sequel (later SQL) created at IBM Research Lab 1979–Oracle markets first relational DB with SQL 1986–ANSI SQL standard released 1989, 1992, 1999, 2003, 2007–Major ANSI standard updates Current–SQL is supported by most major database vendors at 1999, 2003 and 2007

6 The purpose of the SQL standard SQL Syntax and Semantics Intrinsic Data Structures Portability Levels: Minimal (L1) Complete (L2) Allow for Growth / Enhancement

7 Benefits of the SQL standard Reduced training costs Productivity Application portability Application longevity Reduced dependence on a single vendor Cross-system communication Yes. The standard helps, but each of these benefits is not as realized as other standards, such as HTML

8 The SQL Server Environment Server Instance Catalog (db) Schema Objects Catalog (db) Schema Objects In this class we use: SQL Server  ist-s-students.syr.edu Instance . (default) Catalog  ist359yournetid# Schema  dbo (default)

9 SQL Server 2008 R2: ist-s-students Other Information: – SQL Dialect: T-SQL / Transact-SQL – Case Sensitive Collation?: Yes – System tables used to represent meta data. – Client / Server over TCP/IP Connect to database using: host/IP, port number, logon, password Client software used to manage data/meta data on server – Everything can be expressed in SQL! Naming Rules for Objects in SQL Server: – Up to 128 characters long – Must begin with a letter or _, @, # (cannot be a digit) – Can contain digits, letters, _,. – Spaces can be used but should be avoided.

10 My Naming Conventions WhatMike’s ConventionRationale for use All object namesUse all lower case letters.Disambiguation: eg. Employee vs. employee for example All object namesUse underscore in place of SPACE Avoid the need to place brackets around identifiers. employee_phone_number vs. [employee phone number] TablesPluralizeShould be employees table, since it contains more than one employee TablesQualify with logical schemaDisambiguation of objects within the same database: eg. kmart_employees vs. netflix_employees Column namesQualify with table nameHelps define scope of object. Eg. employee_zipcode.vs vendor_zipcode Constraintspk= primary key fk=foreign key u=unique ck=check i=index Disambiguation of constraints, for example: ck_vendor_zipcode.vs. fk_vendor_zipcode

11 SQL: Language Breakdown DomainSQL CommandsObjects Metadata (DDL) CREATE ALTER DROP Tables, functions, views, procedures, etc DATA (DML) C - INSERT R - SELECT U - UPDATE D - DELETE Tables (as a target) Security (DCL) GRANT REVOKE Tables, functions, views, procedures, etc. Transactions (DTL) BEGIN TRANS COMMIT ROLLBACK Controls DML statements

12 Workflow in SQL Mgmt Studio 1.Type in SQL 2.Highlight it 3.Check it (For syntax errors) 4.Wreck it (Execute on Server) 5.Once you execute “the program has run and the damage is done.” There is no undo, only redo, meaning if you delete something to get it back you must start over again.

13 DDL 1 Create students table w/Defaults ID Name Email GPA Year (Fr, So, Jr, Sr) Are they iSchool? DOB?

14 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

15 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

16 DDL2 Students table add constraints Primary Key Unique emails Valid GPA’s

17 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

18 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

19 DML Add students List students Find one student Update students Update one student

20 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

21 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

22 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

23 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

24 Lookup table Create table student_years Add pk to table Add data to student_years Alter students add FK

25 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.

26 Murach’s SQL Server 2008, C10© 2008, Mike Murach & Associates, Inc.


Download ppt "Structured Query Language SQL IST359 M005 Yang Wang 342 Hinds"

Similar presentations


Ads by Google