0% found this document useful (0 votes)
24 views

SQL Excerise

The document shows SQL commands used to create tables, sequences, and insert records in an Oracle database. Tables are created to store employee data with different structures. Records are inserted into the tables and sequences are used to automatically generate primary key values for new records. Records from different tables are selected and viewed to verify the data.

Uploaded by

Sri Vatsa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

SQL Excerise

The document shows SQL commands used to create tables, sequences, and insert records in an Oracle database. Tables are created to store employee data with different structures. Records are inserted into the tables and sequences are used to automatically generate primary key values for new records. Records from different tables are selected and viewed to verify the data.

Uploaded by

Sri Vatsa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SQL> connect

Enter user-name: System

Enter password:

Connected.

SQL> create table employee(empno number(6),empname char(20),empsalary number(10));

Table created.

SQL> alter table employee add commission number(10);

Table altered.

SQL> desc employee

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPNO NUMBER(6)

EMPNAME CHAR(20)

EMPSALARY NUMBER(10)

COMMISSION NUMBER(10)

SQL> insert into employee values(01,'kavya',10000,null);

1 row created.

SQL> insert into employee values(02,'kavi',20000,500);

1 row created.

SQL> insert into employee values(03,'nirmala',18000,200);


1 row created.

SQL> insert into employee values(04,'sandhiya',13000,2000);

1 row created.

SQL> insert into employee values(05,'thendral',8000,null);

1 row created.

SQL> select * from employee;

EMPNO EMPNAME EMPSALARY COMMISSION

---------- -------------------- ---------- ----------

1 kavya 10000

2 kavi 20000 500

3 nirmala 18000 200

4 sandhiya 13000 2000

5 thendral 8000

SQL> create table emp as select * from employee;

create table emp as select * from employee

ERROR at line 1:

ORA-00955: name is already used by an existing object

SQL> create table emps as select * from employee;

Table created.
SQL> select * from emps where empsalary>10000;

EMPNO EMPNAME EMPSALARY COMMISSION

---------- -------------------- ---------- ----------

2 kavi 20000 500

3 nirmala 18000 200

4 sandhiya 13000 2000

SQL> select * from emps where commission is null;

EMPNO EMPNAME EMPSALARY COMMISSION

---------- -------------------- ---------- ----------

1 kavya 10000

5 thendral 8000

SQL> create table emp_1(empid number(6),empname char(10)primary key,empsalary number(10));

Table created.

SQL> desc emp_1;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPID NUMBER(6)

EMPNAME NOT NULL CHAR(10)

EMPSALARY NUMBER(10)

SQL> insert into emp_1 values(100,'kavya',13000);

1 row created.
SQL> insert into emp_1 values(200,'kavi',12000);

1 row created.

SQL> insert into emp_1 values(300,'dhiya',2000);

1 row created.

SQL> insert into emp_1 values(400,'navi',3000);

1 row created.

SQL> insert into emp_1 values(500,'nirmala',20000);

1 row created.

SQL> select * from emp_1;

EMPID EMPNAME EMPSALARY

---------- ---------- ----------

100 kavya 13000

200 kavi 12000

300 dhiya 2000

400 navi 3000

500 nirmala 20000

SQL> create sequence seq start with 50 maxvalue 500 increment by 15 cache 2;

Sequence created.
SQL> create sequence seq1 start with 10 maxvalue 100 increment by 20 cycle cache 2;

Sequence created.

SQL> create sequence seq2 start with 20 maxvalue 200 increment by 20 nocycle cache 2;

Sequence created.

SQL> create table test(eno number(2),ename char(10));

create table test(eno number(2),ename char(10))

ERROR at line 1:

ORA-00955: name is already used by an existing object

SQL> create table tab_emp(eno number(2),ename char(10));

Table created.

SQL> insert into tab_emp values(seq.nextval,'kavya');

1 row created.

SQL> insert into tab_emp values(seq.nextval,'kavi');

1 row created.

SQL> insert into tab_emp values(seq.nextval,'dhiya');

1 row created.
SQL> insert into tab_emp values(seq.nextval,'navi');

1 row created.

SQL> select * from tab_emp;

ENO ENAME

---------- ----------

50 kavya

65 kavi

80 dhiya

95 navi

SQL> insert into tab_emp values(seq1.nextval,'kavya');

1 row created.

SQL> insert into tab_emp values(seq1.nextval,'kavi');

1 row created.

SQL> insert into tab_emp values(seq1.nextval,'dhiya');

1 row created.

SQL> insert into tab_emp values(seq1.nextval,'navi');

1 row created.

SQL> select * from tab_emp;


ENO ENAME

---------- ----------

50 kavya

65 kavi

80 dhiya

95 navi

10 kavya

30 kavi

50 dhiya

70 navi

8 rows selected.

SQL> insert into tab_emp values(seq2.nextval,'kavya');

1 row created.

SQL> insert into tab_emp values(seq2,nextval,'kavi');

insert into tab_emp values(seq2,nextval,'kavi')

ERROR at line 1:

ORA-00913: too many values

SQL> select * from tab

SQL> select * from tab_emp;

ENO ENAME

---------- ----------

50 kavya
65 kavi

80 dhiya

95 navi

10 kavya

30 kavi

50 dhiya

70 navi

20 kavya

9 rows selected.

SQL> create table empp(eno number(5),ename char(20));

Table created.

SQL> insert into empp values (seq.nextval,'kavi');

1 row created.

SQL> insert into empp values (seq.nextval,'kavya');

1 row created.

SQL> insert into empp values (seq.nextval,'navi');

1 row created.

SQL> select * from empp;

ENO ENAME

---------- --------------------
110 kavi

125 kavya

140 navi

SQL> insert into emp values(seq2.nextval,'kavi');

insert into emp values(seq2.nextval,'kavi')

ERROR at line 1:

ORA-00947: not enough values

SQL> insert into empp values(seq2.nextval,'kavi');

1 row created.

SQL> insert into empp values(seq2.nextval,'kavya');

1 row created.

SQL> insert into empp values(seq2.nextval,'kavya');

1 row created.

SQL> select * from empp;

ENO ENAME

---------- --------------------

110 kavi

125 kavya

140 navi

40 kavi
60 kavya

80 kavya

6 rows selected.

You might also like