Day 1
Day 1
Day 1
SQL> create table product ( pid number(3) , pname varchar(20) not null ,
2 price number not null , quantity number(3) not null,
3 primary key(pid) );
Table created.
9 rows selected.
SQL> select *
2 from user_constraints
3 where table_name = 'PRODUCT';
Table created.
SQL> ED
Wrote file afiedt.buf
Table created.
SQL>
SQL> INSERT ALL
2 INTO PRODUCT VALUES ( 1 ,'IPHONE11' ,39999,10)
3 INTO PRODUCT VALUES ( 2 ,'IPHONE12' ,49999, 4)
4 INTO PRODUCT VALUES ( 3 ,'IPHONE13' ,59999, 6)
5 INTO PRODUCT VALUES ( 4 ,'IPHONE14' ,69999, 2)
6 INTO PRODUCT VALUES ( 5 ,'IPHONE15' ,79999, 7)
7 INTO CUSTOMER VALUES (1 , 'ANIL' , 'HYD' ,500082)
8 INTO CUSTOMER VALUES (2 , 'ABHI' , 'CHN' ,600001)
9 INTO CUSTOMER VALUES (3 , 'AKHIL' , 'BNG' ,500001)
10 INTO CUSTOMER VALUES (4, 'RANI' , 'HYD' , 500072)
11 SELECT *
12 FROM DUAL;
9 rows created.
SQL> SELECT *
2 FROM PRODUCT;
SQL> COMMIT;
Commit complete.
SQL> /*
SQL> COPY / DUPLICATE THE TABLE BY USING CREATE
SQL> SYNTAX:
SQL> CREATE TABLE TABLE_NAME
SQL> AS
SQL> SELECT STATEMENT;
SQL>
SQL> ---- WITH RECORDS
SQL> EXAMPLE :
SQL> CREATE TABLE PRODUCT_C
SQL> AS
SQL> SELECT *
SQL> FROM PRODUCT;
SQL> -- WITHOUT RECORDS
SQL> EXAMPLE :
SQL> CREATE TABLE PRODUCT_D
SQL> AS
SQL> SELECT *
SQL> FROM PRODUCT
SQL> WHERE 1=0;
SQL> */
SQL> CREATE TABLE PRODUCT_C
2 AS
3 SELECT *
4 FROM PRODUCT;
Table created.
SQL> SELECT *
2 FROM CAT;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
STUDENT TABLE
EMPLL TABLE
E TABLE
DUM TABLE
PRODUCT TABLE
CUSTOMER TABLE
ORDERS TABLE
TABLE_NAME TABLE_TYPE
------------------------------ -----------
PRODUCT_C TABLE
12 rows selected.
SQL> SELECT *
2 FROM PRODUCT_C;
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'PRODUCT';
Table created.
13 rows selected.
-----------------------------------------------------------------------------------
----------------
PID
PNAME
PRICE
QUANTITY
SQL> SELECT *
2 FROM PRODUCT_D;
no rows selected
Table dropped.
SQL> SELECT *
2 FROM TAB;
13 rows selected.
Flashback complete.
SQL> SELECT *
2 FROM TAB;
13 rows selected.
SQL> DROP TABLE P;
Table dropped.
Flashback complete.
SQL> SELECT *
2 FROM TAB;
13 rows selected.
Table dropped.
Table created.
Flashback complete.
14 rows selected.
Table purged.
SQL> SELECT *
2 FROM TAB;
13 rows selected.
Table dropped.
SQL> SELECT *
2 FROM TAB;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
STUDENT TABLE
EMPLL TABLE
E TABLE
DUM TABLE
PRODUCT TABLE
CUSTOMER TABLE
ORDERS TABLE
PRODUCT_C TABLE
12 rows selected.
SQL> -- TRUNCATE
SQL> -- USED REMOVE / DELETE ALL ROWS/ RECORDS PERMANENTLY FROM TABLE
SQL> SELECT *
2 FROM PRODUCT_C;
Table truncated.
SQL> SELECT *
2 FROM PRODUCT_C;
no rows selected
Table renamed.
Table altered.
SQL> DESC P;
Name Null? Type
----------------------------------------------------- --------
------------------------------------
PID NUMBER(3)
PNAME NOT NULL VARCHAR2(20)
PRICE CHAR(5)
QUANTITY NOT NULL NUMBER(3)
Table altered.
SQL> DESC P;
Name Null? Type
----------------------------------------------------- --------
------------------------------------
PID NUMBER(3)
PNAME NOT NULL VARCHAR2(20)
PRICE NOT NULL CHAR(5)
QUANTITY NOT NULL NUMBER(3)
Table altered.
SQL> DESC P;
Name Null? Type
----------------------------------------------------- --------
------------------------------------
PID NUMBER(3)
PNAME NOT NULL VARCHAR2(20)
PRICE NOT NULL NUMBER
QUANTITY NOT NULL NUMBER(3)
Table altered.
SCOTT SYS_C007655 C P
"PRICE" IS NOT NULL
SCOTT SYS_C007648 C P
"QUANTITY" IS NOT NULL
SCOTT SYS_C007656 U P
Table altered.
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'P';
SCOTT SYS_C007655 C P
"PRICE" IS NOT NULL
SCOTT SYS_C007648 C P
"QUANTITY" IS NOT NULL
Table altered.
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'P';
SCOTT SYS_C007648 C P
"QUANTITY" IS NOT NULL
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'P';
Table altered.
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'P';
SCOTT SYS_C007648 C P
"QUANTITY" IS NOT NULL
Table altered.
SQL> SELECT *
2 FROM USER_CONSTRAINTS
3 WHERE TABLE_NAME = 'P';
SQL>