Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ex 1: Ex 2:
CREATE TABLE Dept CREATE TABLE Emp
(Deptno CHAR(5) NOT (Empno CHAR(5) NOT
NULL PRIMARY KEY, NULL PRIMARY KEY, Ename
Deptname CHAR(20)); CHAR(20) NOT NULL,
Desig CAHR(20), Grade
CHAR(2), Salary
NUMBER(10,2) CHECK
(Salary > 10000.00),
Joindate DATE DEFAULT
SYSDATE, Deptno CHAR(5)
NOT NULL REFERENCES
Dept.Deptno);
Note the Following:
Ex 1: Ex 2:
INSERT INTO Emp INSERT INTO Emp
(empno,ename,desig,grad (empno,ename,desig,grad
e,salary,deptno) VALUES e,salary,deptno) VALUES
(‘100’,’Rajan (‘&1’,’&2’,’&3’,’&4’,&5,’&6’);
Singh’,’Engineer’,’A’,20000,’
213’);
Note the Following
Ex-2 makes use of parameter substitution. Unfortunately, parameter
substitution is not available with MySql. When EX-2 is executed in
SQL * Plus, it prompts the user to enter the values of respective
columns. By executing the same command again and again user can
create several rows in the table. In MySql we have to edit the same
command again and again using up/ down arrow keys to add sevaral
rows.
In SQL*Plus the & symbol acts as the parameter substitution
operator. When a substitution variable is used SQL*Plus prompts for
the value of the variable, accepts it and substitutes it in place of
variable.
In SQl*Plus we can use EDIT command to correct the SQL Syntax
errors. Another way of doing the same thing may be saving the query
in a file and then edit that file as:
SQL> SAVE query1
SQL * Plus saves the contents of buffer in a file called query1.sql. Now to
run the query we can use following commands
SQL> GET query1
SQL> RUN