Beginning SQL, Differences Between Oracle and Microsoft



Similar documents
Oracle Migration Workbench

How To Create A Table In Sql (Ahem)

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL

SQL Server An Overview

SQL Server to Oracle A Database Migration Roadmap

Oracle Database: Introduction to SQL

Using SQL Server Management Studio

Oracle Database 11g SQL

Database Migration from MySQL to RDM Server

4 Logical Design : RDM Schema Definition with SQL / DDL

Oracle Database 12c: Introduction to SQL Ed 1.1

ORACLE TO SYBASE ASE MIGRATION GUIDE

Success Keys For Migrating From Sybase ASE to DB2 UDB

Porting from Oracle to PostgreSQL

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

Ontrack PowerControls V8.1 for SQL ReadMe

Programming with SQL

Guide to Migrating from DB2 to SQL Server

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

Mini User's Guide for SQL*Plus T. J. Teorey

Database Management Systems Comparative Study: Performances of Microsoft SQL Server Versus Oracle

Oracle to MySQL Migration

Oracle 10g PL/SQL Training

Migrating from Sybase to SQL Server

Database Migration : An In Depth look!!

Advanced SQL. Jim Mason. Web solutions for iseries engineer, build, deploy, support, train

news from Tom Bacon about Monday's lecture

Using Temporary Tables to Improve Performance for SQL Data Services

Oracle Database 10g: Introduction to SQL

Guide to Upsizing from Access to SQL Server

Migration to SQL Server With Ispirer SQLWays 6.0

Introduction to Database. Systems HANS- PETTER HALVORSEN,

SQL Server 2008 Core Skills. Gary Young 2011

4 Simple Database Features

Instant SQL Programming

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

A Migration Methodology of Transferring Database Structures and Data

Tutorial: How to Use SQL Server Management Studio from Home

Performance Management of SQL Server

Best Practices in SQL Programming. Madhivanan

ODBC Client Driver Help Kepware, Inc.

Comparison of Open Source RDBMS

Advanced Query for Query Developers

SharePlex for SQL Server

Setting up SQL Translation Framework OBE for Database 12cR1

Ontrack PowerControls User Guide Version 8.0

An Oracle White Paper June Migrating Applications and Databases with Oracle Database 12c

Oracle Database Architecture Overview

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle SQL. Course Summary. Duration. Objectives

Oracle Database: SQL and PL/SQL Fundamentals

INTRODUCTION TO DATABASE SYSTEMS

Migrating Non-Oracle Databases and their Applications to Oracle Database 12c O R A C L E W H I T E P A P E R D E C E M B E R

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

MySQL Command Syntax

SQL Server Table Design - Best Practices

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

MS Designing and Optimizing Database Solutions with Microsoft SQL Server 2008

SQL Server. SQL Server 100 Most Asked Questions: Best Practices guide to managing, mining, building and developing SQL Server databases

Using TimesTen between your Application and Oracle. between your Application and Oracle. DOAG Conference 2011

ORACLE DATABASE 11G: COMPLETE

Chapter 2: Security in DB2

MapInfo SpatialWare Version 4.6 for Microsoft SQL Server

Database Administration with MySQL

Database Extension 1.5 ez Publish Extension Manual

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

INSTALLATION INSTRUCTIONS FOR THE STUDENT SAMPLE SCHEMA

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

5.1 Database Schema Schema Generation in SQL

Data Transfer Management with esync 1.5

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

Oracle Database 12c Enables Quad Graphics to Quickly Migrate from Sybase to Oracle Exadata

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Welcome to the topic on queries in SAP Business One.

Implementing Microsoft SQL Server 2008 Exercise Guide. Database by Design

3.GETTING STARTED WITH ORACLE8i

ATTACHMENT 6 SQL Server 2012 Programming Standards

10+ tips for upsizing an Access database to SQL Server

SQL Server In-Memory OLTP Internals Overview for CTP2

DATABASE ADMINISTRATION SQL SERVER STANDARDS

Oracle/SQL Tutorial 1

ICAB4136B Use structured query language to create database structures and manipulate data

Saskatoon Business College Corporate Training Centre

Microsoft SQL connection to Sysmac NJ Quick Start Guide

SQL. Short introduction

Chapter Replication in SQL Server

Black Hat Briefings USA 2004 Cameron Hotchkies

David Dye. Extract, Transform, Load

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

not at all a manual simply a quick how-to-do guide

Information Systems SQL. Nikolaj Popov

MS-40074: Microsoft SQL Server 2014 for Oracle DBAs

Transcription:

Beginning SQL, Differences Between and Microsoft If you're new to SQL or just new to SQL, perhaps coming from a Microsoft environment, it may seem like the two versions should be very similar, and they are, to a certain degree, but they are also very different in some important and basic ways. You may need to know these differences because of a migration effort from one to the other, or because you need to access both of them in your day-to-day operations. Perhaps you have an server being downloaded into a SQL Server data warehouse, or perhaps you have distributed databases being uploade into a consolidating database. For these and other circumstances under which these two exist, you may need to be aware of the differences between the two versions of the SQL language. So what are the differences from to? Part I. A Quick Intro for the User Don't Use Databases Well, first of all, we don't use databases, we connect to them: use mydatabase connect mydatabase/mypassword Use Dual And then, our select statements have different options, in this instance requiring a from clause: select getdate(); select getdate() from dual; so we use that dummy we call DUAL. Did you notice the lack of a from clause in the first version? It's a nice shortcut, but doesn't allow it, nor does ANSI SQL92. Select Into And we don't select rows into a table, but instead, insert the rows by selecting

them: select getdate() mycolumn into mytable; insert into mytable select sysdate() mycolumn from dual; Actually, the version creates a table if one doesn t exist, so the version would require a CREATE TABLE AS statement to arrive at the same result. Inserts By the way, the into clause of an insert statement is not an option on ; it's required: insert mytable values('more text'); Updates insert into mytable values('more text'); What about updates? Well, these are different too, and may have to be rewritten entirely to replace the from clause used to get data from one or more tables: update mytable set mycolumn=myothertable.mycolumn from mytable,myothertable where mytable.mycolumn like 'MY%' and myothertable.myothercolumn='some text'; Deletes update mytable set mycolumn= (select a.mycolumn from myothertable a where myothertable.myothercolumn='some text'; ) where mytable.mycolumn like 'MY%'; And finally, the delete requires a FROM clause in :

delete mytable where mycolumn like 'some%'; delete from mytable where mycolumn like 'some%'; which we always try to double-check in either case. Notice that we used a link for thattable on thatdb, which is considered to be a remote database. Vendor Programs So where is all this taking place? What programs are we running on? Well, in place of isql, we're using SQL*Plus to enter our statements, and in place of the Northwind examples, we use Scott's tiger: command-line-prompt:isql or, for queries developed in SQL Analyzer: command-line-prompt: osql use northwind command-line-prompt:sqlplus scott/tiger Notice that we didn't have to use the connect statement because it's automatic when you first login. Now that we're logged in, we can query Scott's infamous tables, EMP and DEPT, to execute the examples we find in various reference materials such as the SQL*Plus User's Guide and others. And now, we're off on our own to pursue our education in SQL further. Welcome aboard! Part II. A Little More Detail Outer Join Now, where would we be without the outer join? Missing data, that's where. So, here's an example of that query in dialects:

Select d.deptname,e.empname from dept d, emp e WHERE d.empno *= e.enum; Select d.deptname,e.empname from dept d, emp e WHERE d.empno = e.enum (+); Notice the slight syntactic difference shown in this example from Scott's beloved EMP and DEPT tables. This may seem like completely opposite forms of expressing this statement, nevertheless all departments are listed even though some have no employees. Sub-queries in Place of Columns Another extension over both SQL92 and, is the use of sub-queries wherever a column name is allowed. Here, the quarterly sales columns are returned by a sub-query on the sales table to produce a single row listing all four quarters results for the year: select distinct year, q1 = (select Amount amt FROM sales where Quarter=1 AND year = s.year), q2 = (SELECT Amount amt FROM sales where Quarter=2 AND year = s.year), q3 = (SELECT Amount amt FROM sales where Quarter=3 AND year = s.year), q4 = (SELECT Amount amt FROM sales where Quarter=4 AND year = s.year) from sales s; SELECT year, DECODE( quarter, 1, amount, 0 ) q1, DECODE( quarter, 2, amount, 0 ) q2, DECODE( quarter, 3, amount, 0 ) q3, DECODE( quarter, 4, amount, 0 ) q4 FROM sales s; The same one-line result is produced by the decode function, which is reported by to be faster than the sub-queries and actually looks like a simpler swatch of code than the select statements. Deletes With Second From Clause Deleting rows from one table conditionally based on the contents of rows in another table can be expressed with a statement containing two from clauses:

delete from products from products, product_deletes where products.a = product_deletes.a and products.b = product_deletes.b and product_deletes.c = 'd'; delete from products where ( a, b ) in ( select a, b from product_deletes where c = 'd' ); This can be rewritten to a statement using a single FROM clause, even if there is a multi-column join, with a sub-query to produce the same effect of deleting only those rows marked for the purpose in the other table. Part III. More Depth The Connect Concept provides connection to a server which allows access to multiple databases, while 's Server provides access to one database with multiple users and roles, so a database is roughly equivalent to a tablespace, user, schema and role. One can change roles or connect as a different user, but the one server, one database concept remains. For all the similarities between the two SQL versions, there are a few key conceptual differences: A : Database owner, DBO Group/Role Non-unique Index Transact SQL stored procedure T-SQL stored procedure Trigger Complex rule Column identity property is an : Schema Role Index PL/SQL procedure PL/SQL function BEFORE trigger AFTER trigger Sequence And a few that are only available in : Clusters Packages Triggers for each row Synonyms Snapshots

Data Type Differences Here's a summary of the datatype differences between the two versions: INTEGER SMALLINT TINYINT REAL FLOAT BIT VARCHAR(n) TEXT IMAGE BINARY(n) VARBINARY DATETIME SMALL-DATETIME MONEY NCHAR(n) NVARCHAR(n) SMALLMONEY TIMESTAMP SYSNAME NUMBER(10) NUMBER(6) NUMBER(3) FLOAT FLOAT NUMBER(1) VARCHAR2(n) CLOB BLOB RAW(n) or BLOB RAW(n) or BLOB DATE DATE NUMBER(19,4) CHAR(n*2) VARCHAR(n*2) NUMBER(10,4) NUMBER VARCHAR2(30), VARCHAR2(128) As you may imagine, there are also differences in the concepts of data storage, such as page versus data block, but our purposes are limited to SQL. Time 's default time storage in the date datatype resolves down to the second, while 's DATETIME datatype will store to the 1/300th second, but the new TIMESTAMP datatype will store 1/100 millionth of a second in accuracy, if one remembers to use it instead of the default type. See the Migration Guide for an extended example on this subject. Alias A column alias is useful sometimes in cutting down the clutter in an SQL statement: select a=deptid,b=deptname,c=empno from dept; select deptid a, deptname b, empno c from dept; One can think of these as being the reverse of each other, as a memory aid, with the version coming before the the column name and the version coming after it.

Sub-queries SELECT ename, deptname FROM emp, dept WHERE emp.enum = 10 AND(SELECT security_code FROM employee_security WHERE empno = emp.enum) = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level); SELECT empname, deptname FROM emp, dept WHERE emp.empno = 10 AND EXISTS (SELECT security_code FROM employee_security es WHERE es.empno = emp.empno AND es.security_code = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level)); Both versions of SQL support multiple subqueries, but with differing syntax. The select in place of a column name in can produce the same effect as the query within the subquery in, which is the version supported by SQL92. Part III: Something New With the recent update of SQL to support the use of regular expressions, the expressive power of simple queries is greatly expanded. New features have been introduced for this purpose, such as the operator REGEXP_LIKE and the functions REGEXP_INSTR, REGEXP_SUBSTR, and REGEXP_REPLACE. We can now write queries for non-digit zipcodes in one, short statement: select zip from zipcode where regexp_like (zip, '[^[:digit:]]') This one shows the starting column of both the 5 and 9 digit

zip code: SELECT REGEXP_INSTR('Joe Smith, 10045 Berry Lane, San Joseph, CA 91234-1234', ' [[:digit:]]{5}(-[[:digit:]]{4})?$') AS starts_at FROM dual Further examples can be found in the excellent article, on OTN, written by Alice Rischert. Summary This discussion has been an attempt at a light and lively introduction to the database world for those familiar with the Microsoft database products. Much more in-depth examples are available in the references shown that follow, from which many of the examples were drawn and for which we can thank the authors involved. References (1) Migration Workbench Reference Guide for and Sybase Adaptive Server Migrations, Release 9.2.0 for Microsoft Windows 98/2000/NT and Microsoft Windows XP, Part Number B10254-01 (2) Microsoft Transact-SQL Reference: http://msdn.microsoft.com/library/default.asp?url=/library/enus/tsqlref/ts_tsqlcon_6lyk.asp (4) Technology Network, OTN: http://otn.oracle.com/software/index.html As puts it: "All software downloads are free, and each comes with a development license that allows you to use full versions of the products only while developing and prototyping your applications. You can buy products

with full-use licenses at any time from the online Store or from your sales representative." (5) Writing Better SQL Using Regular Expressions, By Alice Rischert http://otn.oracle.com/oramag/webcolumns/2003/techarticles/rischert_regexp_ pt1.html