0% found this document useful (0 votes)
40 views8 pages

Create Table Salesman

The document outlines the creation of several database tables including 'salesman', 'customer', and 'orders', along with their respective fields and constraints. It also details the insertion of records into these tables, highlighting various errors encountered during the process, such as syntax issues and missing commas. Finally, it presents successful queries that retrieve data from the tables, including counts of customers by grade and salesmen with multiple customers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views8 pages

Create Table Salesman

The document outlines the creation of several database tables including 'salesman', 'customer', and 'orders', along with their respective fields and constraints. It also details the insertion of records into these tables, highlighting various errors encountered during the process, such as syntax issues and missing commas. Finally, it presents successful queries that retrieve data from the tables, including counts of customers by grade and salesmen with multiple customers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

create table salesman (salesman_id number(4),name varchar(20),city varchar(20),commission

varchar2(20),primary key(salesman_id));

Table created.

SQL> create table customer1(customer_id number(4),cust_name varchar(20),city varchar(20),grade


number(3),primary key(customer_id),salesman_id reference salesman(salesman_id) on delete set
null);

create table customer1(customer_id number(4),cust_name varchar(20),city varchar(20),grade


number(3),primary key(customer_id),salesman_id reference salesman(salesman_id) on delete set
null)

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> create table customer1 (customer_id number(4),customer_name varchar(20),city


varchar2(20),grade number(3),primary key(customer_id),salesman_id reference
salesman(salesman_id) on delete set null);

create table customer1 (customer_id number(4),customer_name varchar(20),city varchar2(20),grade


number(3),primary key(customer_id),salesman_id reference salesman(salesman_id) on delete set
null)

ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> create table customer(customer_id number(4),cust_name varchar(20),city varchar(20),grade


number(3),primary key(customer_id),salesman_id references salesman(salesman_id) on delete set
null);

Table created.

SQL> create table orders(ord_no number(5),purchase_amt number(10,2),ord_date date,primary


key(ord_no),customer_id references customer(customer_id)on delete cascade,salesman_id
references salesman(salesman_id) on delete cascade);
Table created.

SQL> desc salesman;

Name Null? Type

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

SALESMAN_ID NOT NULL NUMBER(4)

NAME VARCHAR2(20)

CITY VARCHAR2(20)

COMMISSION VARCHAR2(20)

SQL> desc customer;

Name Null? Type

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

CUSTOMER_ID NOT NULL NUMBER(4)

CUST_NAME VARCHAR2(20)

CITY VARCHAR2(20)

GRADE NUMBER(3)

SALESMAN_ID NUMBER(4)

SQL> desc orders;

Name Null? Type

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

ORD_NO NOT NULL NUMBER(5)

PURCHASE_AMT NUMBER(10,2)

ORD_DATE DATE

CUSTOMER_ID NUMBER(4)

SALESMAN_ID NUMBER(4)

SQL> insert into salesman values(1000,'john','banglore','25%');


1 row created.

SQL> insert into salesman values(2000,'ravi',banglore',20%');

insert into salesman values(2000,'ravi',banglore',20%')

ERROR at line 1:

ORA-00917: missing comma

SQL> insert into salesman values(2000,'ravi',banglore','20%');

ERROR:

ORA-01756: quoted string not properly terminated

SQL> insert into salesman values(2000,'ravi','banglore','20%');

1 row created.

SQL> insert into salesman values(3000,'kumar','mysore','15%');

1 row created.

SQL> insert into salesman values(4000,'smith','delhi','30%');

1 row created.

SQL> insert into salesman values(5000,'harsha',hydrabad','15%');

ERROR:

ORA-01756: quoted string not properly terminated


SQL> insert into salesman values(5000,'harsha','hydrabad','15%');

1 row created.

SQL> insert into customer values(10,'preeti','banglore',100,1000);

1 row created.

SQL> insert into customer values(11,'vivek','manglore',300,1000);

1 row created.

SQL> insert into customer values(12,'bhaskar','chennai',400,2000);

1 row created.

SQL> insrt into customer values(13,'chethan','banglore',200,2000);

SP2-0734: unknown command beginning "insrt into..." - rest of line ignored.

SQL> insert into customer values(13,'chethan','banglore','200,2000);

ERROR:

ORA-01756: quoted string not properly terminated

SQL> insert into customer values(13,'chethan','banglore',200,2000);

1 row created.

SQL> insert into customer values(14,'mamatha','banglore',400,3000);

1 row created.
SQL> insert into order values(50,5000,'04-may-17',10,1000);

insert into order values(50,5000,'04-may-17',10,1000)

ERROR at line 1:

ORA-00903: invalid table name

SQL> insert into order values(50,5000,'04-may-17',10,1000);

insert into order values(50,5000,'04-may-17',10,1000)

ERROR at line 1:

ORA-00903: invalid table name

SQL> insert into orders values(50,5000,'04-may-17',10,1000);

1 row created.

SQL> insert into orders values(51,450,'20-jan-17',10,2000);

1 row created.

SQL> insert into orders values(52,1000,'24-feb-17',13,2000);

1 row created.

SQL> insert into orders values(53,'3500'

SQL> insert into orders values(53,3500,'13-apr-17',14,3000);

1 row created.
SQL> insert into orders values(54,550,'09-mar-17',12,2000);

1 row created.

SQL> select*from salesman;

SALESMAN_ID NAME CITY COMMISSION

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

1000 john banglore 25%

2000 ravi banglore 20%

3000 kumar mysore 15%

4000 smith delhi 30%

5000 harsha hydrabad 15%

SQL> select*from customer;

CUSTOMER_ID CUST_NAME CITY GRADE SALESMAN_ID

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

10 preeti banglore 100 1000

11 vivek manglore 300 1000

12 bhaskar chennai 400 2000

13 chethan banglore 200 2000

14 mamatha banglore 400 3000

SQL> select*from orders;

ORD_NO PURCHASE_AMT ORD_DATE CUSTOMER_ID SALESMAN_ID

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

50 5000 04-MAY-17 10 1000

51 450 20-JAN-17 10 2000


52 1000 24-FEB-17 13 2000

53 3500 13-APR-17 14 3000

54 550 09-MAR-17 12 2000

SQL> select grade,count(distinct costomer_id)from customer group by grade having grade having
grade>(select avg(grade) from customer where city='banglore');

select grade,count(distinct costomer_id)from customer group by grade having grade having


grade>(select avg(grade) from customer where city='banglore')

ERROR at line 1:

ORA-00920: invalid relational operator

SQL> select grade,count(distinct customer_id)from customer group by grade having grade having
grade>(select avg(grade) from customer where city='banglore');

select grade,count(distinct customer_id)from customer group by grade having grade having


grade>(select avg(grade) from customer where city='banglore')

ERROR at line 1:

ORA-00920: invalid relational operator

SQL> select grade,count(distinct customer_id)from customer group by grade having grade>(select


avg(grade) from customer where city='banglore');

GRADE COUNT(DISTINCTCUSTOMER_ID)

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

300 1

400 2

SQL> select salesman_id,name from salesman A where 1<(select count(*) from customer where
salesman_id=A.salesman_id);
SALESMAN_ID NAME

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

1000 john

2000 ravi

SQL> committe

SP2-0042: unknown command "committe" - rest of line ignored.

SQL>

You might also like