|
还是有很多的不同,转贴如下:http://www.bristle.com/Tips/SQL.htm#Oracle%20Tips
Table of Contents:
- Oracle Tips
- SQL Tips
- SELECT * and more
- Materialized View
- PL/SQL Tips
- SQL Navigator Tips
- See Also
- MS SQL Server Tips
- SQL Tips
- Dynamic SQL in a Stored Procedure
- SQL Enterprise Manager Tips
- Keyboard Shortcuts
- SQL Generating SQL
- See Also
- Differences Between Oracle and MS SQL Server
- Concepts and Terminology
- Data Types
- Limits
- Operators
- Built-In Functions
- Differences in SQL Syntax
- Differences in SQL Semantics
- Differences in Managing Databases
- Differences in Managing Database Objects
- Differences in Managing Users
- Differences in Integration with MS ADO, RDO, etc.
- Miscellaneous Differences
- See Also
Details of Tips:
Oracle Tips
SQL Tips
This section contains tips on standard SQL (Structured Query Language) statements in Oracle.
SELECT * and more
Last Updated: 6/6/1999 Applies to: Oracle 7.3, 8 (and probably earlier versions)
To select all columns of a table: select * from table
However, to select all real columns, plus a pseudo-column like "user": select table.*, user from table
The following does not work: select *, user from table
--Fred
Materialized View
Last Updated: 1/7/2002 Applies to: Oracle 8+
Oracle 8i introduced a new feature called a "materialized view". You define it just like any other view, except that you add the keyword MATERIALIZED: CREATE MATERIALIZED VIEW view_name
A materialized view is like a combination of a table and a view. Like a view, it is defined as a logical view into the data of one or more tables. When you update the tables, subsequent queries of the view see the updated data. However, like a table, its data is stored in the database. Also, like a table, it is faster if you define indexes for it.
A regular view is stored as a mapping of data from tables. When you modify the data in the tables, the view is completely ignored. When you access the view, it joins the data currently in the tables, and returns the data you requested. A materialized view is stored as such a mapping along with a copy of the actual data from the tables. When you modify the data in the tables, the view''''s copy of the data is also updated. When you access the view, the data is drawn directly from the copy.
Thus a materialized view makes table updates a little slower, but makes view queries much faster. It also consumes additional space in the database.
You could accomplish the same effect by defining an additional table instead of the view, and using triggers on the component tables to update it each time they are changed. However, using a materialized view is more convenient, more efficient, and clearer to the next person who has to maintain your database.
Thanks to Andy Glick for sending me a sample of a materialized view from his application!
--Fred
PL/SQL Tips
This section contains tips on PL/SQL statements -- the Oracle "procedural language" superset of SQL that you use to write stored procedures.
SQL Navigator Tips
This section contains tips on the SQL Navigator tool by Quest Systems. It is a graphical front end to the Oracle database, allowing you to create, delete, view, and modify all Oracle objects: tables, views, stored procedures, etc.
See Also
Last Updated: 6/6/1999 Applies to: Oracle 7.3+
The following are good sources of info about Oracle:
- Koch, George, and Kevin Loney. Oracle 8, The Complete Reference. Berkeley CA: For Oracle Press by Osborne McGraw-Hill, 1997. ISBN 0-07-882396-X.
This book includes introductory database concepts as well as a complete reference to Oracle SQL and PL/SQL statements. The companion CD contains a complete copy of the book, so you can read it on-line, search it, etc.
- Any of the O''''Reilly books. I''''ve been very impressed by all of the O''''Reilly books since my early Unix and X-Windows days in the 80''''s, and they have a complete series on Oracle, covering PL/SQL, the standard packages, etc.
--Fred
MS SQL Server Tips
SQL Tips
This section contains tips on SQL (Structured Query Language) statements in MS SQL Server.
Dynamic SQL in a Stored Procedure
Last Updated: 2/7/1999 Applies to: MS SQL Server 6.5+
A typical tradeoff for a database application is dynamic SQL (SQL commands embedded in the application -- for flexibility) vs. stored procedures (pre-compiled SQL procedures stored in the database and invoked by name from the application -- for speed and control over what SQL statements get executed). However, you can have the best of both worlds by using dynamic SQL inside your stored procedures. In a stored procedure, you can use the EXEC statement to execute a string of SQL statements that you built dynamically in the stored procedure or read from the database or any other data source.
Thanks to Steve Rhoads for this tip.
--Fred
SQL Enterprise Manager Tips
This section contains tips on the SQL Enterprise Manager tool. It is a graphical front end to the database, allowing you to create, delete, view, and modify all MS SQL Server objects: tables, views, stored procedures, etc.
Keyboard Shortcuts
Last Updated: 6/20/1999 Applies to: MS SQL Server 7.0
Here is a list of some of the more useful shortcut keys in SQL Enterprise Manager.
| Key |
Function |
F1
Help on SQL Enterprise Manager
Shift-F1
Help on syntax of current SQL statement
Ctrl-E
Execute selected text in Query Analyzer
Ctrl-R
Hide/show results pane in Query Analyzer
Obviously, this list is far from complete. Please feel free to mail me your favorite shortcuts. I''''ll add to this list as time permits.
See also: Windows Shortcut Keys
--Fred
SQL Generating SQL
Last Updated: 2/7/1999
Applies to: MS SQL Server 6.5+
To automate tedious database maintenance chores, you can use SQL statements to generate SQL statements that do your maintenance for you. For example, to change the permissions on all stored procedures in a database, you can use a SELECT statement like:
SELECT ''''GRANT EXECUTE ON '''' + name + '''' TO PUBLIC
GO''''
FROM sysobjects
WHERE type = ''''P''''
The output of this SELECT statement is a series of alternating GRANT and GO statements, one pair per stored procedures, for all stored procedures in the database. Then you copy that output as your next set of commands and execute it.
Note: Be sure to leave the line break before the word GO. It is required to start on a new line, after the GRANT statement.
Thanks to Steve Rhoads for this tip.
--Fred
See Also
Last Updated: 6/6/1999
Applies to: MS SQL Server 6.5+
The following are good sources of info about MS SQL Server:
- MS SQL Server books on the MSDN Library CD.
--Fred