0% found this document useful (0 votes)
15 views4 pages

3 Oct 23

The document shows SQL commands being run to create, alter, insert into and select from tables. Tables for departments, persons and teams are created with various columns. Data is inserted and selected. Errors are encountered and addressed. The team1 table is duplicated into a new team2_department table by selecting and inserting the data.

Uploaded by

iqbalsohaib38
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

3 Oct 23

The document shows SQL commands being run to create, alter, insert into and select from tables. Tables for departments, persons and teams are created with various columns. Data is inserted and selected. Errors are encountered and addressed. The team1 table is duplicated into a new team2_department table by selecting and inserting the data.

Uploaded by

iqbalsohaib38
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL*Plus: Release 11.2.0.2.

0 Production on Tue Oct 3 10:12:05 2023

Copyright (c) 1982, 2014, Oracle. All rights reserved.

SQL> connect system;


Enter password:
Connected.
SQL> desc dept;
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPT_ID NUMBER(10)
DEPT_NAME VARCHAR2(50)

SQL> alter table dept


2 add dept_loc varchar2(50);

Table altered.

SQL> drop table dept;

Table dropped.

SQL> create table dept


2
SQL> create table person
2 (Person_id number(10),
3 Person_name varchar2(50),
4 person_age varchar2(50));

Table created.

SQL> alter table person


2 add constraint pk112 primary key (person_age);

Table altered.

SQL> insert into person values(1,'Sufi',21);

1 row created.

SQL> insert into person values(2,'Mueed',21);


insert into person values(2,'Mueed',21)
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.PK112) violated

SQL> drop table person;

Table dropped.

SQL> create table person


2 (Person_id number(10),
3 Person_name varchar2(50));

Table created.

SQL> alter table person


2 add
3 person_age number(10);

Table altered.

SQL> desc person;


Name Null? Type
----------------------------------------- -------- ----------------------------
PERSON_ID NUMBER(10)
PERSON_NAME VARCHAR2(50)
PERSON_AGE NUMBER(10)

SQL> alter table person


2 modify person_age not null;

Table altered.

SQL> desc person;


Name Null? Type
----------------------------------------- -------- ----------------------------
PERSON_ID NUMBER(10)
PERSON_NAME VARCHAR2(50)
PERSON_AGE NOT NULL NUMBER(10)

SQL> create team1_department


2 (deptno number(10),
3 deptname varchar2(50),
4 loc varchar2(50));
create team1_department
*
ERROR at line 1:
ORA-00901: invalid CREATE command

SQL> create table team1_department


2 (deptno number(10),
3 deptname varchar2(50),
4 loc varchar2(50));

Table created.

SQL> create synonym team1 for team1_department;

Synonym created.

SQL> insert into team1 values(10,'Accounting','New York');

1 row created.

SQL> insert into team1 values(20,'Research','DALLAS');

1 row created.

SQL> insert into team1 values(20,'SALES','CHICAGO');

1 row created.

SQL> alter table team1


2 ;
*
ERROR at line 2:
ORA-02210: no options specified for ALTER TABLE

SQL> update team1 set deptid=30 where loc='CHICAGO';


update team1 set deptid=30 where loc='CHICAGO'
*
ERROR at line 1:
ORA-00904: "DEPTID": invalid identifier

SQL> update team1 set deptno=30 where loc='CHICAGO';

1 row updated.

SQL> select * from team1;

DEPTNO DEPTNAME
---------- --------------------------------------------------
LOC
--------------------------------------------------
10 Accounting
New York

20 Research
DALLAS

30 SALES
CHICAGO

SQL> create table team2_department


2 (deptno number(10),
3 deptname varchar2(50),
4 loc varchar2(50));

Table created.

SQL> insert into team2_department(deptno,deptname,loc)


2 select deptno,dname,loc
3 from team 1;
from team 1
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> insert into team2_department(deptno,deptname,loc)


2 select deptno,deptname,loc
3 from team 1;
from team 1
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> insert into team2_department(deptno,deptname,loc)


2 select deptno,deptname,loc
3 from team1;

3 rows created.

SQL> select * from team2_department;

DEPTNO DEPTNAME
---------- --------------------------------------------------
LOC
--------------------------------------------------
10 Accounting
New York

20 Research
DALLAS

30 SALES
CHICAGO

SQL>

You might also like