Sunteți pe pagina 1din 6

The following commands can be issued in SQL*Plus (in addition to the standard SQL commands.

)
@ pathname Run an SQL Script (see START) @MyScript.sql parameter1 parameter2 parameter3 In the SQL-Script, refer to the parameters as &1, &2, and &3.

@@ pathname Run a nested SQL Script. / ACCEPT Execute (or re-execute) commands in the SQL*Plus buffer does not list commands before running User input ACC[EPT] variable [NUM[BER]|CHAR|DATE] [FORMAT format] [DEFAULT default] [PROMPT text|NOPROMPT] [HIDE] Add text to the end of the current line in the buffer. A[PPEND] text_to_add Specify where and how formatting will change. BREAK ON {column|expr|ROW|REPORT} action Place and format a title at the bottom of each page. BTITLE printspec [text|variable] BTITLE [OFF|ON] Change text on the current line. C /oldval/newval Clear the SQL*Plus screen and the screen buffer. CLEAR {BREAKS|BUFFER|COLUMNS|COMPUTES|SCREEN|SQL TIMING} Change display width of a column. Calculate and display totals. Connect to a database as a specified user. connect username/password@SID Copy data from a query into a table (local or remote) User variables: DEFINE varName = String Display a user variable DEFINE varName Display all variables DEFINE DEFINE_EDITOR = sql*plus editor (e.g. DEFINE_EDITOR=vim.exe) DEL DESC[RIBE] Delete the current line in the SQL buffer Describe a table, column, view, synonym, function procedure, package or package contents.

APPEND BREAK BTITLE

CHANGE CLEAR COLUMN COMPUTE CONNECT COPY DEFINE

DISCONNECT EDIT EXECUTE EXIT [n] GET file HELP topic HOST INPUT LIST n m

Logoff (but don't exit) Load the SQL*Plus buffer into an editor. By default, saves the file to AFIEDT.BUF Run a single PLSQL statement EXEC :answer := EMP_PAY.BONUS('SMITH') Commit, logoff and exit (n = error code) EXIT SQL.SQLCODE Retrieve a previously stored command file Topic is an SQL PLUS command or HELP COMMANDS Execute a host operating system command HOST CD scripts Edit sql buffer - add line(s) to the buffer Edit sql buffer - display buffer lines n to m For all lines - specify m as LAST Wait for the user to hit RETURN List the value of a bind variable or REF Cursor (see Echo a message to the screen or /* comment */

PAUSE message PRINT variable VARIABLE / SHOW) PROMPT message REMARK RUN RUNFORM SAVE file SET SHOW

REMARK comment or --comment--

Execute (or re-execute) commands in the SQL*Plus buffer Lists the commands before running Run a SQL*Forms application Save the contents of the SQL*Plus buffer in a command file SAVE file [CRE[ATE] | REP[LACE] | APP[END]] Display or change SQL*Plus settings List the value of a system variable (see PRINT)

SHUTDOWN [ABORT|IMMEDIATE|NORMAL|TRANSACTIONAL] SPOOL file SPOOL OFF SQLPLUS STA[RT] Store query results in file Turn off spooling SPOOL OUT sends file to printer Start SQL*Plus and connect to a database. Run an SQL Script (see @)

STARTUP [NoMOUNT|MOUNT|OPEN]

TIMING TTITLE UNDEFINE VARIABLE

Record timing data TIMING {START | SHOW | STOP} see CLEAR TIMING Define a page title Delete a user variable or passed parameter (see DEFINE) Define a bind variable (Can be used in both SQLPlus and PLSQL) VAR[IABLE] [variable {NUMBER|CHAR|CHAR (n)}] VARIABLE on its own will display the definitions made. Exit if an OS error occurs Exit if an SQL or PLSQL error occurs

WHENEVER OSERROR WHENEVER SQLERROR

Primary key:

What is a primary key?


A primary key is a single field or combination of fields that uniquely defines a record. None of the fields that are part of the primary key can contain a null value. A table can have only one primary key. Note: In Oracle, a primary key can not contain more than 32 columns. A primary key can be defined in either a CREATE TABLE statement or an ALTER TABLE statement.

Using a CREATE TABLE statement


The syntax for creating a primary key using a CREATE TABLE statement is: CREATE TABLE table_name (column1 datatype null/not null, column2 datatype null/not null, ... CONSTRAINT constraint_name PRIMARY KEY (column1, column2, . column_n) );

For example: CREATE TABLE supplier ( supplier_id numeric(10) not null, supplier_name varchar2(50) not null, contact_name varchar2(50), CONSTRAINT supplier_pk PRIMARY KEY (supplier_id) ); In this example, we've created a primary key on the supplier table called supplier_pk. It consists of only one field - the supplier_id field.

We could also create a primary key with more than one field as in the example below: CREATE TABLE supplier ( supplier_id numeric(10) not null, supplier_name varchar2(50) not null, contact_name varchar2(50), CONSTRAINT supplier_pk PRIMARY KEY (supplier_id, supplier_name) );

Using an ALTER TABLE statement


The syntax for creating a primary key in an ALTER TABLE statement is: ALTER TABLE table_name add CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n);

For example: ALTER TABLE supplier add CONSTRAINT supplier_pk PRIMARY KEY (supplier_id); In this example, we've created a primary key on the existing supplier table called supplier_pk. It consists of the field called supplier_id.

We could also create a primary key with more than one field as in the example below: ALTER TABLE supplier add CONSTRAINT supplier_pk PRIMARY KEY (supplier_id, supplier_name);

Drop a Primary Key


The syntax for dropping a primary key is: ALTER TABLE table_name drop CONSTRAINT constraint_name;

For example: ALTER TABLE supplier drop CONSTRAINT supplier_pk; In this example, we're dropping a primary key on the supplier table called supplier_pk.

Disable a Primary Key


The syntax for disabling a primary key is: ALTER TABLE table_name disable CONSTRAINT constraint_name;

For example: ALTER TABLE supplier disable CONSTRAINT supplier_pk; In this example, we're disabling a primary key on the supplier table called supplier_pk.

Enable a Primary Key

The syntax for enabling a primary key is: ALTER TABLE table_name enable CONSTRAINT constraint_name;

For example: ALTER TABLE supplier enable CONSTRAINT supplier_pk; In this example, we're enabling a primary key on the supplier table called supplier_pk.

S-ar putea să vă placă și