![]() ![]() ![]() ![]() |
| Topics this page: |
| Screen: Max • 1024 • 800
|
|
Maximum... | MS-SQL | Oracle |
---|---|---|
Rows per Table | - | unlimited |
Database size | (2005) 32 terabytes (2008) 524,272 TB | - |
Log file size | 4 TB | - |
BLOB, CLOB, NCLOB, BFILE bytes | - | 4GB |
Page extent contiguous size | 64 KB (8 pages) | - |
size of SQL Procedure | - | 64KB |
Page block size | 8 KB (8,192) = header: 96 bytes body: 8096 bytes | - |
bytes per row | 8,060 | (9i) 2000 (10g) 4000 |
char type bytes | 8,000 | 255 |
Pages tracked by each PFS (Page Free Space) page | 8,000 | - |
UDT size | (2005) 8,000 (2008) unlimited | - |
VARCHAR2 / NVARCHAR2 & ROWID / UROWID bytes | n/a | 4,000 |
int type value | 2.147 billion (2^31) | - |
Tables per Database | 2 billion | - |
Objects open per Database | 2,147,483,647 | - |
Users and roles in database | - | 2,147,483,638 |
LONG and Long Raw type bytes | - | 2 billion |
smallmoney type value | $214,748.0000 | - |
Money decimal precision | 4 (.4444) | - |
Files per Database | - | 65,533 |
smallint type value User Connections databases per server instance | 32,767 | - |
Files per database | 32,767 | - |
Filegroups per database | 256 | - |
Parameters per stored procedure or UDF (user defined function) | 2,100 | - |
Files per physical Oracle Tablespace/MS-SQL Filegroup | - | 1,022 (OS dep.) |
Columns per SELECT statement | 4,096 | - |
Columns per INSERT statement | 1,024 | - |
Columns per non-wide base table Columns per (2008) wide table | 1,024 30,000 | 1,000 |
Columns in composite index. primary/foreign key | 16 | 32 |
Tables per SELECT statement | 256 | - |
Non-clustered indexes per table | (2005) 249 (2008) 999 | - |
Characters in Table / Column Name | 30 | 30 |
Index column key size bytes | 900 | - |
Levels for nesting in stored procedures, subqueries, trigger levels | 32 | - |
Clustered indexes per table | 1 | - |
This page compares the capacity limitations of Oracle vs. Microsft SQL Server databases.
SQL is pronounced either as a sequence of letters "Es-Queue-Ell" or as acronym "Sequel".
Microsoft: Maximum Capacity Specifications for SQL Server
Yahoo Computers and Internet > Programming and Development > Languages > SQL
MySQL AB was created by Monty Widenius.
MySQL Enterprise Solutions
(Indianapolis, Ind. : John Wiley & Sons, Inc. (US), 2003)
by Pachev, Alexander "Sasha"
|
Action | Oracle SQL | Microsoft SQL |
---|---|---|
Language Name | PL/SQL - Procedural Language | Transact-SQL |
Tool for interactive input, store, and running of stored procedures |
|
SQLW
|
Batch invocation | - | ![]()
|
Read product documentation | - | For Books online: Within SQLW, Help toolbar -> Building SQL Server Applications -> Transact-SQL Reference -> System Stored Procedures (T-SQL) |
Return to the OS | exit | - |
To control output | set serveroutput on set serverout off | SET NOCOUNT ON |
Send output to a file | spool myoutput.out | - |
Stop sending output | spool off | - |
Send output file to printer (for lpr) | spool out | - |
To invoke SQL statements stored in file named my.sql | start my.sql | - |
View properties about an object | select * from all_views |
sp_help 'object_name'
or sp_helptext 'object_name' for unencrypted comments in the syscomments system catalog table. |
Text sourceof all stored objects belonging to the user | user_source | - |
Tool to trap activitybetween client app and SQL to a flat file | - | SQL Server Profiler |
Comment operator |
-- double hyphen or between /* and */ |
-- double hyphen or IF 1 = 0 -- never true
PRINT 'Line 2'; |
To execute a procedure in the buffer |
start or @ (ampersand) | ? |
To execute SQL script in the buffer |
. dot run; or / (slash) |
GO or F5 key or Ctrl-E |
To concatenate and print | DBMS_OUTPUT.PUT_LINE ( 'hello' || v_name ); | - |
Ending a block | period ends each PL/SQL block | ; semicolon ends each SQL block. |
Every time an Oracle user invokes SQL*Plus, two scripts are also automatically executed:
| ![]() ![]() ![]() |
|
Value | Oracle SQL | Microsoft SQL |
---|---|---|
- | - | select @@Connections; select @@Max_Connections; |
Session Id of each connection in the current user process | - | select @@SPID; select @@ProcID; |
% CPU Busy & Idle | - | select @@CPU_Busy; select @@Idle; |
% IO Busy | - | select @@IO_Busy; |
Number of Rows in most current statement. | - | select @@Cursor_Rows; |
The first day of the the week (1 to 7) specified by SET DATEFIRST. | - | select @@DateFirst; |
timestamp (datatype varbinary) provides the last-used rowversion value of the current database. A new rowversion value is generated when a row with a rowversion column is inserted or updated. | - | select @@DBTS; |
The error number of previous SQL command (used instead of TRY/CATCH) | - | select @@Error; select @@Fetch_Status; |
- | - | select @@Total_Errors; |
Count of reads and writes | - | select @@Total_Read; select @@Total_Write; |
Unlike SCOPE_IDENTITY(), not scope-specific way to get a unique id to the last auto-incremented record added among all tables during a session. | - | select @@Identity; |
Language Identifier | - | select @@LangID; select @@Language; |
- | - | select @@Lock_TimeOut; |
- | - | select @@Max_Precision; select @@TimeTicks; |
- | - | select @@Pack_Received; select @@Pack_Sent; |
- | - | select @@RemServer; select @@ServerName; select @@ServiceName; |
- | - | select @@TextSize; |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
Oracle SQL | Microsoft SQL |
---|---|
NVL( column_name, value_if_null )
NVL( num_field, 0 ) NVL( txt_field, "NULL" ) |
ISNULL( column_name, value_if_null )
ISNULL( price, $0.00 ) ISNULL( SSN, 'NNN-NN-NNNN' ) |
In T-SQL, the COALESCE function below is often used to set the current database to work with if a database name is not specified in the input parameter:
SET @dbname = COALESCE(@dbnameParam, DB_NAME()) SELECT @dbname AS [Database Name], ...
In Oracle, to calculate numbers or display text not from any table, use the special dummy table owned by Oracle user sys:
|
Action | Oracle SQL | Microsoft SQL |
---|---|---|
Format US Social Security (9 digit) Number | - | SELECT STUFF(STUFF('123456789',4,0,'-'),7,0,'-') |
Convert a small number of fixed values | decode( weekday, 1,'Sun', 2,'Mon', 3,'Tue', 4,'Wed', 5,'Thu', 6,'Fri', 7,'Sun', '???') | - |
Datatypes and Value Assignment |
skalar char, number, long, date, and varchar2
as in
price := qty*(cost*2.5); plus v_valid_order boolean not null := true; and tables | - |
Set date format just for current session | alter session set nls_date_format = 'YYYY-MON-DD-HH24:MI:ss' | SET DATEFORMAT |
Identify date of table | - | SELECT crdate FROM sysobjects WHERE name = 'mytable' |
Create Custom Datatype | - | EXEC sp_addtype @typename=typeSSN, @phystype='CHAR(11)', @nulltype='NOT NULL' |
Create a Table with a Check Constraintusing a custom data type typeSSN | - |
CREATE TABLE SSNTable ( EmployeeID INT PRIMARY KEY, EmployeeSSN typeSSN,
( EmployeeSSN LIKE '[0-9][0-9][0-9]—[0-9][0-9]—[0-9][0-9][0-9][0-9]' ) |
Encryption | - | SET ENCRYPTION ON -- Introduced with SQL 2008, enables cell-level Transparent Data Encryption (TDE) using Data Encryption Key (DEK). |
Date Time User Defined Functions
T-SQL 2008 allows SELECT $identity FROM ... to display values of the identity (ID) column for the table.
|
Type of Constraint | Oracle | MS-SQL |
---|---|---|
list constraints | select constraint_name from user_constraints; | ? |
Domain integrityby limiting acceptable values for a column entry. |
- | CHECK |
PRIMARY KEYA table can only have one column to uniquely identify rows. However, a composite index can consist of up to 16 columns. |
- | CONSTRAINT tab1_pk PRIMARY KEY (col1, col2)
If this is not specified, the MS-SQL default is to create a clustered index which stores data in physical order within leaf nodes containing data pages which are linked in a doubly-linked list implemented as a B-tree index structure that supports fast retrieval of the rows based on their clustered index key values. Tables created with a non-clustered index are called heaps with leaf nodes containing index rows. A covering index includes all columns referenced in the query such that the index contains the data sought in order to avoid looking up actual data in the table -- good If applications perform the same query over and over on the same table. |
UNIQUE Entity integrityA non-primary key column is unique among all rows. |
- | By default, a nonclustered index is created for each such column. Each combination of columns that could uniquely identify rows in a table is called a candidate key. |
NOT NULL |
- | Special processing for null values degrade performance. |
FOREIGN KEYA foreign key in one table points to a primary key in another table. |
- | ALTER TABLE table1 col_a INT NULL CONSTRAINT tab1_fk1 REFERENCE table2(tab1_col_pk) |
IDENTITY property(starting IdentitySeed, IdentityIncrement) |
- | ALTER TABLE table1 ADD Identity_column INT IDENTITY(1,1) GO Whether a table has an identity column can be determined using the OBJECTPROPERTY function. This can be selected using the IDENTITYCOL keyword. |
To turn off Identify checking temporarily (for ETL) | - | SET IDENTITY_INSERT mytable On; INSERT mytable (IdentityColumnID, etc. ) ... SET IDENTITY_INSERT mytable Off; |
| ![]() ![]() ![]() |
|
Action | Oracle SQL | Microsoft SQL |
---|---|---|
Create Index | - |
Syntax: CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED] INDEX index_name ON table (column [,...n]) [WITH [PAD_INDEX] [[,] FILLFACTOR = fillfactor] [[,] IGNORE_DUP_KEY] [[,] DROP_EXISTING] [[,] STATISTICS_NONRECOMPUTE] [ON filegroup] |
Which tables in a database may need indexes?
| ![]() | ![]() ![]() ![]() |
|
Action | Oracle | MS-SQL |
---|---|---|
Create statistics on every column supporting statistics in the current database | sp_createstats | |
Create statistics data from the table. | CREATE STATISTICS | |
When were statistics last updated? | STATS_DATE | |
Determines whether a particular statistic will be automatically updated. | sp_createstats | |
The density of an existing statistic set. | DBCC_SHOW_STATISTICS | |
Update statistics data from the table. | UPDATE STATISTICS | |
Remove statistics data from the table. | DROP STATISTICS |
To rebuild all indexes in a MS-SQL database, schedule an undocumented procedure to execute during CPU idle time and slow production periods:
|
Statistic | Description |
---|---|
Pages Scanned |
Number of pages in the table or index found during scanning. |
Extents Scanned |
Number of physical extents among pages scanned. |
Extent Switches |
Number of times the DBCC statement left an extent while it traversed the pages of the extent. |
Avg. Pages per Extent |
Number of pages per extent in the page chain. |
Scan Density |
100 percent if everything is contiguous. The smaller this value, the more fragmentation exists. The best count is the ideal number of extent changes that would be necessary if everything were contiguously linked. The actual count is the actual number of extent changes. |
Logical Scan Fragmentation |
The percentage of out-of-order pages returned from scanning the leaf pages of an index. |
Extent Scan Fragmentation |
Percentage from a count of out-of-order pages divided by the count of all leaf pages of an index scanned. |
Avg. Bytes free per page |
The absolute number of free bytes averaged over all pages scanned. Lower values are better because they make fuller use of each page. Higher row sizes make this number worse. |
Avg. Page density (full) |
Percentage of each page's bytes of useful data divided by the total bytes of all pages scanned. Higher values are better because they make fuller use of each page. make fuller use of each page. er worse. |
| ![]() ![]() ![]() |
|
Action | Oracle SQL | Microsoft SQL |
---|---|---|
Create/Alter View | - |
CREATE VIEW testview AS NOTE: T-SQL has no ALTER VIEW IF EXISTS |
List Views defined | select view_name from user_views; | - |
Display read I/O | - |
SET STATISTICS_IO ON |
Display Clustered indexes usedin optimized query Execution Plans (algorithms) | - |
SET SHOWPLAN_TEXT ON or SET SHOWPLAN_ALL ON for resource costing estimates or graphical SHOWPLAN in SQL Server Query Analyzer |
Update Statistics Used for Auto Indexing | - |
UPDATE STATISTICS or UPDATE STATISTICS NORECOMPUTE to stop updating |
Display database linkages and sizes | - | DBCC CHECKTABLE |
Get
| - |
SELECT OBJECT_ID('PUBS..TITLES') GO DBCC SHOWCONTIG(123456789) number from Data Base Consistency Checker response DBCC CHECKTABLE displays linkages and sizes |
Sync view metadata with view | - | sp_refreshview 'viewname' |
Avoid ORDER BY within views unless TOP is used.
Views cannot access temporary tables.
|
Information Stored | Oracle Data Dictionary View Name | Microsoft MS-SQL |
---|---|---|
A list of current errors on all objects accessible to the user | all_errors | . |
Text source of all stored objects accessible to the user | all_source | . |
Current errors on all stored objects in the database | dba_errors | . |
All PL/SQL objects in the database | dba_object_size | . |
Text source of all stored objects in the database | dba_source | . |
Current errors on all a user's stored objects | user_errors | . |
Text source of all stored objects belonging to the user | user_source | . |
User's PL/SQL objects | user_object_size | . |
Top 50 CPU bound statements (Queries Expensive for CPU) |
- | SELECT TOP 50 (a.total_worker_time/a.execution_count) as [Avg_CPU_Time], Convert(Varchar,Last_Execution_Time) as 'Last_execution_Time', Total_Physical_Reads, SUBSTRING(b.text,a.statement_start_offset/2, (case when a.statement_end_offset = -1 then len(convert(nvarchar(max), b.text)) * 2 else a.statement_end_offset end - a.statement_start_offset)/2) as Query_Text, dbname=Upper(db_name(b.dbid)), b.objectid as 'Object_ID' FROM sys.dm_exec_query_stats a cross apply sys.dm_exec_sql_text(a.sql_handle) as b ORDER BY [Avg_CPU_Time] DESC |
|
Action | Oracle SQL | Microsoft SQL |
---|---|---|
Control structures |
PL/SQL extensions to SQL: conditional if-then-else | - |
Control structures |
PL/SQL extensions to SQL:
iterative for-loop sequential while-loop & end loop; exit-when unconditional flow-control goto | - |
Labels to go to | << SampleLabel >>. | - |
Sequential processing using a cursor |
declare cursor each_emp is select ename, sal from emp where deptno = 30; emp_name varchar2(20); emp_sal number(7,2); begin open each_emp; loop fetch each_emp into emp_name, emp_sal; if each_emp%NOTFOUND then exit; end if; emp_sal := emp_sal + (emp_sal * .10); end loop; close each_emp; end; |
use payroll declare @ename as varchar(20) declare @emp_sal as decimal(7,2) DECLARE @each_emp CURSOR FOR SELECT ename, pay_rate FROM emp inner join pay on emp.emp_id = pay.emp_id where deptno = 30 OPEN each_emp FETCH NEXT FROM emp_cursor into @emp_name, @emp_sal WHILE @@FETCH_STATUS = 0 BEGIN
FETCH NEXT FROM each_emp into @emp_name, @emp_sal DEALLOCATE each_emp END |
Related functions and cursors stored together | Packages | - |
Table support |
declare type emp_table_type is table of varchar2(35) index by binary_integer; emp_table emp_table_type; i binary_integer := 0; cursor each_emp is select ename from emp; begin open each_emp; loop i := i + 1; fetch each_emp into emp_table(i); if each_emp%NOTFOUND then exit; end if; end loop; statement(s); -- work with emp_table(1), emp_table(2), etc. close each_emp; end; |
EXEC CREATE TABLE emp_table (column1 INT NOT NULL, column2 CHAR(10) NOT NULL)
GO
EXEC sp_help emp_table
SELECT emp_table FROM INFORMATION_SCHEMA.TABLES
|
Debugging |
Public package dbms_output creates a buffer to accept
dbms_output.put or put_line commands.
set serverout displays the buffer. |
exec sp_addmessage 50500, 14, 'msg'
creates error code 50500 with severity 14 at state 1.
raiseerror (50500,14,1)
|
SQL_RoboPERF procedure reports
| ![]() ![]() ![]() |
|
Item/Object | add/drop/help Stored Procedure EXEC ... | To get a list: SELECT createdate, updatedate, accdate, ... FROM server.database.owner.object | Executive GUI |
---|---|---|---|
NT Network Accounts | Domain SAM | ||
SQL Login | dbname, loginname, isntgroup FROM master..syslogins (view of master table sysxlogins) | ||
Databases | sp_helpdb database_name | name, filename, crdate FROM master..sysdatabases | |
Columns | TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS | ||
Privileges | * FROM INFORMATION_SCHEMA.TABLES_PRIVELEGES | ||
Database User Accounts | sp_addlogin login, name_in_db | uid, name from northwind..sysusers where islogin = 1 | |
sp_grantdbaccess login, name_in_db | |||
sp_grantlogin login, name_in_db
or GRANT CREATE VIEW, CREATE PROCEDURE, CREATE TABLE TO cathy | |||
sp_revokelogin, sp_denylogin login, name_in_db
or REVOKE CREATE VIEW, CREATE PROCEDURE TO cathy | |||
sp_denylogin login, name_in_db
or DENY CREATE VIEW, CREATE PROCEDURE TO cathy | |||
Permissions for Uid's | uid, action, protecttype from northwind..sysprotects | ||
Fixed Server Role | sp_addsrvrolemember @loginame, @rolename | name from master..syslogins system table | for Logins |
Fixed Database Role | sp_addrolemember role, security_account | name from northwind..sysusers where issqlrole = 1 | |
Database Standard User Role | sp_addrole @rolename, @ownername | name from northwind..sysusers where issqluser = 1 | |
Application Role | sp_addapprole @rolename, @password GO sp_setapprole @rolename, @password | name from northwind..sysusers where isapprole = 1 | |
Primary Data Files | CREATE DATABASE library ON PRIMARY ( name=library_data, FILEname='c:\mssql7\data\library.mdf', size=10MB, MAXsize=15MB, FILEGROWTH=20%)
DROP DATABASE library | ...\*.mdf containing 8KB data pages (128 pages per MB) | |
Secondary Data Files | ...\*.ndf containing 8KB data pages (128 pages per MB) | ||
Log Files | ... LOG ON ( name=library_log, FILEname='c:\mssql7\data\library.ldf', size=3MB, MAXsize=5MB, FILEGROWTH=1MB) | C:\Mssql7\Log\*.ldf (sized 25% of data file by default) | |
File Groups | ALTER DATABASE northwind ADD FILEGROUP orderhistorygroup GO |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
The Oracle "opened cursors cumulative" metric Oracle configuration item OPEN_CURSORS specifies the maximum number of open cursors a session is allowed to have at once in order to prevent a session from opening too many cursors. This parameter is needed to constrain the size of the PL/SQL cursor cache PL/SQL uses. Having enough save avoids the need to reparse statements reexecuted by users.
|
Unlike a GUI cursor, a databse cursor is an area of memory which holds data fetched from the database. Global cursors are deallocated when the connection ends. Local cursors are limited to a single procedure.
A database cursor is a variable that runs through the tuples of some relation. This relation can be a stored table or the answer to a query. Fetching into the cursor each tuple of the relation allows processing the value of each such tuple. If the relation is stored, we can also update or delete the tuple at the current cursor position.
This example is shown because cursors are more efficient than SET transactions at calculating running sums (cumulative totals) and at dynamic DDL Code iteration.
PL/SQL example:
DECLARE v_cnt NUMBER; c1rec NUMBER; CURSOR c1 IS SELECT * FROM customers; BEGIN OPEN c1; FETCH c1 INTO c1rec;
Declaring a SCROLL CURSOR allows you to fetch backward with these commands:
Declaring a CURSOR INSENSITIVE makes it not sensitive to changes in the table and won't refresh.
To determine how many rows have been affected by the executable statement:
Oracle provides built-in cursor ATTRIBUTE SQL%ROWCOUNT, one of Oracle's four built-in cursor ATTRIBUTES to determine the status of cursors:
To link a row updated to the latest row fetched inside a cursor called row_cur:
UPDATE x SET due_dt = sysdate + 2 WHERE CURRENT OF row_cur;
Cursor variables allow different SQL SELECT statements.
To define a Oracle PL/SQL procedural block using an explicit cursor:
INSERT INTO employee VALUES (6, 'TOM LEE', 10000);
UPDATE employee SET sal = sal + 5000 WHERE empno = 6;
SELECT sal INTO v_sal FROM employee WHERE empno = 6;
COMMIT;
EXECUTE procedure
EXCEPTION --optional error handling code
| ![]() ![]() ![]() |
|
Action | Oracle | MS-SQL |
---|---|---|
Get a list of triggers |
. | SELECT trigger_name 'INSERT'=object_name(instrig), 'UPDATE'=object_name(updtrig), 'DELETE'=object_name(deltrig), FROM sysobjects WHERE type = 'U' AND (instrig <> 0 OR updtrig <> 0 OR deltrig <> 0) |
Create a new trigger |
. | CREATE OR REPLACE TRIGGER trigger_name after logon -- after logoff -- after servererror -- after startup -- after shutdown -- after create -- after drop -- after alter ON table FOR ( [DELETE] [,] [INSERT] [,] [UPDATE] } [WITH ENCRYPTION] AS sql_statement |
Drop a trigger |
. | DROP TRIGGER trigger_name |
Step | Action |
---|---|
1 | Execute before statement triggers. |
2 | Loop for each row affected by the SQL statement. a. Execute before row triggers. b. Lock and change rows, check for integrity constraints. |
3 | Complete deferred integrity constraint checking. |
4 | Execute after statement triggers. |
| ![]() ![]() ![]() |
| Itzik Ben-Gan's Microsoft SQL Server 2008 T-SQL Fundamentals Inside Microsoft SQL Server 2008: T-SQL Programming (Microsoft Press, 2009). | ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() Administrating SQL 7.0 #70-028 Braindump Implementing SQL 7.0 #70-029 Braindump
2005 Exams are retiring March 2009, so MS has reduced their price 40% from $125 to $75.
MCITP: Database Administrator certification 70-447 Upgrade from 2000 to 2005 Inside SQL Server 2005 books "T-SQL Querying", "T-SQL Programming", and "Query Tuning and Optimization". | ![]() ![]() ![]() |
| ![]() ![]() ![]() |
![]()
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page ![]() Thank you! |