Thursday, April 21, 2016

Advanced Topics in SQL - SQL tutor / class in NYC New York Manhattan

SQL tutor / class in NYC New York Manhattan
Basic Topics:
Executing a Simple Query
Working with Functions
Organizing Data
Retrieving Data from Multiple Tables using Joins
Presenting Query Results
Querying Using Subqueries
Manipulating Table Data
Views
Indexing
Transactions
Decision
Format
Stored Procedures
Automation


Converting numbers to dates using timestamps. - this is topic of Orcale SQL, but I guess I will get something related to SQL Server.

Exceptions, error handling in the code
http://logicalread.solarwinds.com/sql-server-exception-handling-try-catch-throw-mc03/#.Vxj1I_l97IU
http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/

Handling duplicates

Date functions
http://www.w3schools.com/sql/sql_dates.asp
https://technet.microsoft.com/en-us/library/aa258265(v=sql.80).aspx
https://msdn.microsoft.com/en-us/library/ms186724.aspx

Intercept, except, union, union all - the differences between them

Inline Table-Valued Functions
https://technet.microsoft.com/en-us/library/ms189294(v=sql.105).aspx
https://www.youtube.com/watch?v=hs4mReAzESc

Recursive Queries,
This is done using CTE - where we will keep doing some recursion until we are done

APPLY Operator,



Offset Window

TOP and OFFSET-FETCH;


http://dbadiaries.com/new-t-sql-features-in-sql-server-2012-offset-and-fetch

Data Modification; Working with Date and Time;
http://sqlmag.com/t-sql/t-sql-classic-date-functions

Questions on Date:
http://www.sql-server-helper.com/faq/dates-p01.aspx
Many interesting questions are listed on:
http://stackoverflow.com/questions/tagged/sql-date-functions

Programmable Objects, Transactions and Concurrency, Exception Handling); In-Memory OLTP.

Along the course you will learn how to use T-SQL to solve practical problems such as:

Relational Division, Missing and Existing Ranges (Gaps and Islands),

Separating Elements, Pivoting and Unpivoting, Ranking and Offset, Running Totals, Moving

Averages, YTD, Custom Aggregations, Dynamic Analysis of Grouping Sets, TOP and

OFFSET-FETCH Problems,

Paging,

Data De-Duplication,

Handling Sequences,

Merging Data,

Treatment of Temporal Intervals (Intersection, Max Concurrent, Packing),

Dynamic Filtering,

Migrating On-Disk to Memory Optimized Data,

Internals and index tuning,

including coverage of Column store data, index access methods, temporary

tables,

set vs. cursors,
http://stackoverflow.com/questions/24168/why-are-relational-set-based-queries-better-than-cursors

Cursors enable manipulation of whole result sets at once. In this scenario, a cursor enables the rows in a result set to be processed sequentially. In SQL procedures, a cursor makes it possible to define a result set (a set of data rows) and perform complex logic on a row by row basis.

query tuning using query.

Triggers

HIERARCHYID datatype
https://www.simple-talk.com/blogs/2012/04/24/hierarchical-queries-with-common-table-expressions/

New York
New York city
Manhattan
SQL Tutor Trainer


Sunday, April 3, 2016

Dynamic SQL

Dynamic SQL




Example from AdventureWorks:
http://www.sqlusa.com/bestpractices/dynamicsql/
http://sqlusa.com/bestpractices/training/scripts/dynamicsql/
https://www.mssqltips.com/sqlservertip/1160/execute-dynamic-sql-commands-in-sql-server/
http://stackoverflow.com/questions/2588013/dynamic-sql-to-query-an-adventureworks-table
http://www.sqlteam.com/article/using-dynamic-sql-in-stored-procedures
http://oakdome.com/programming/SQL_DynamicSQL_sp_executesql.php
http://www.kodyaz.com/articles/t-sql-pivot-tables-in-sql-server-tutorial-with-examples.aspx
https://www.brentozar.com/archive/2013/11/filtered-indexes-and-dynamic-sql/

Dynamic SQL and Procedures:
https://www.youtube.com/watch?v=MiAwOoelu9k

SQl Server Dynamic SQL:
https://www.youtube.com/watch?v=jS3kpNavKM8

Dynamic SQL / Adhoc SQL (6 min short video):
https://www.youtube.com/watch?v=aRr6q4V0sXY

Table names would vary at run time and schema would vary at runtime:
https://www.youtube.com/watch?v=n3odG4bl4LE

Advanced SQL

Advanced SQL consist of new queries in SQL

There is over 100 videos and interview questions on: https://www.youtube.com/user/kudvenkat

i want to master of joins, paritition, views, trigger, dynamicswql

what database do you practice?
functions, proc, in oracle pl sql
i have both oracle sql and ms server 2008

try 2 question for today
1.
find the 2nd highest salary of employees table

2. list employees alongwith their manager in employees table

this was asked in interview with me in the currentjo

3. find information of those employees whose salary is greater than average salary of their respective departments
after that query that I sent you
it returns 1st row of each join no matter how many matches are there
if in two tables you only want to join first row and no other row
you need to use row_number, partition by and subquery
this question is trending now in interviews



select * from employees x, (select DEPARTMENT_ID,avg(salary) avg_salary from employees group by department_id) y where x.department_id=y.department_id and x.salary>y.avg_salary;
this is query to compare salary of each employee against avg salary of department and display only those with highest salary

can you write query to select max salary for each department?
using cte
WITH cteRowNum AS ( SELECT DeptID, EmpName, Salary, DENSE_RANK() OVER(PARTITION BY DeptID ORDER BY Salary DESC) AS RowNum FROM EmpDetails ) SELECT DeptID, EmpName, Salary FROM cteRowNum WHERE RowNum = 1;

These analytical functions are known as window function in sql server

CTE:
http://sql-beginner.blogspot.co.il/2012/09/difference-between-cte-and-sub-query.html
https://technet.microsoft.com/en-us/library/ms190766(v=sql.105).aspx

https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL
https://technet.microsoft.com/en-us/library/ms186243%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396
https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_10002.htm#i2077142
dynamic sql