Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Quick recap of the SQL & the GUI way in Management Studio The Adwentureworks database from the book A script to create tables & insert data for the Amazon.

Similar presentations


Presentation on theme: "1 Quick recap of the SQL & the GUI way in Management Studio The Adwentureworks database from the book A script to create tables & insert data for the Amazon."— Presentation transcript:

1 1 Quick recap of the SQL & the GUI way in Management Studio The Adwentureworks database from the book A script to create tables & insert data for the Amazon example INSERT UPDATE DELETE SELECT (simple) SELECT... ORDER BY SELECT... GROUP BY SELECT - aggregates DISTINCT & ALL predicates Steen Jensen, autumn 2013

2 You can either type in SQL commands in the Query window Or you can do it visually by right-clicking A small live demo! 2 New database Demo created and expanded

3 The Adwentureworks database can be downloaded, so all examples from the book can be tried out Unfortunately there seems to be a problem with Windows 8 – it works fine on my old Windows 7 machine, but doesnt work on Windows 8 The database can be unzipped from Adwentureworks databaseAdwentureworks database Some good advice: Unpack the zip file into the C drive (avoid long/deep paths) After you have unpacked the database, you can attach it in SQL Server Studio by following the screenshots shown in the next slide 3

4 4

5 5 Try to install the Adwentureworks database on your machine Use max. 15 minutes – if it doesnt work, then skip it!

6 To help you get up an running quickly with your Amazon example, you can execute a script, which will create the necessary tables for you and put content into them (if you prefer to make it yourself, this is perfectly fine!) Before you can execute the script, you must make a database and call it Amazon Open a new query window and copy paste the content from the file booksCreateInsert.txt into the query window booksCreateInsert.txt Press on the execute button, and the tables will now be created with content If you expand the Amazon database, you should be able to see the new tables under Tables 6

7 The following slides will be based upon the examples, which can be unzipped from the file Beginning SQL - Final.zip – all examples will be from the file Chap03.sql Beginning SQL - Final.zip Is used to insert new tuples/rows into a table In two flavours: Without column names With column names You can also insert more than one tuple/row at a time (multirow insert) 7

8 Is used to change/update one or more attributes/columns in a table Also possible with expressions 8

9 Is used to delete one or more tuples/rows in a table NB!!! SQL Server may refuse to delete specific rows due to referential integrity violation 9

10 Is used to select/show one or more attribute(s) / column(s) from a table This is called a simple select – also possible with two or more tables join (covered next time) SELECT * FROM...: the asterisk (*) means select all attributes/columns A select will automatically select all tuples/rows, unless you add a WHERE clause 10

11 11

12 12

13 13 The ORDER BY clause is used to order the shown tuples/rows in a specific order You can add the keyword ASC or DESC after ORDER BY to specify the order : ASC: ascending order – default DESC: descending order

14 14 The GROUP BY clause is used to aggregate info Alias

15 15 Aggregates are functions, which work on groups of data Apart from GROUP BY other functions exist: AVG – computing averages MIN and MAx selects the smallest/biggest value within a group COUNT counts the number of occurrences within a group HAVING can be used to specify limitations/rules for a group

16 16 The DISTINCT predicate can be used to avoid showing duplicate tuples/rows The ALL predicate works just the oppsite – not very common!

17 Experiment trying out the different SQL DML commands with your Amazon example (and/or The AdwentureWorks database, if it works!) Try the following commands: INSERT UPDATE DELETE (you can e.g. delete one of the new rows, you insert) SELECT Select with all attributes/columns Select with chosen attributes/columns Select with WHERE clause Select with ORDER BY Select with aggregates (GROUP BY … see slide 15) Select with DISTINCT 17


Download ppt "1 Quick recap of the SQL & the GUI way in Management Studio The Adwentureworks database from the book A script to create tables & insert data for the Amazon."

Similar presentations


Ads by Google