diff --git a/OS/bash/Week4/SQLPlus.md b/OS/bash/Week4/SQLPlus.md new file mode 100644 index 0000000..cdbafb5 --- /dev/null +++ b/OS/bash/Week4/SQLPlus.md @@ -0,0 +1,146 @@ +Credentials + +`CCE230953344@ictorcl` +`student` + +## SQL Logs +```sql +SQL> create table PERSON(driver_id# varchar(30) primary key,name varchar(50),address varchar(100)); + +Table created. + +SQL> desc person + Name Null? Type + ----------------------------------------- -------- ---------------------------- + DRIVER_ID# NOT NULL VARCHAR2(30) + NAME VARCHAR2(50) + ADDRESS VARCHAR2(100) + +SQL> create table CAR(regno varchar(20) primary key,model varchar(30),year int); + +Table created. + +SQL> create table ACCIDENT(report_number int, accd_date date, location varchar(50)); + +Table created. + +SQL> desc accident + Name Null? Type + ----------------------------------------- -------- ---------------------------- + REPORT_NUMBER NUMBER(38) + ACCD_DATE DATE + LOCATION VARCHAR2(50) + +SQL> alter table accident add constraint pkey primary key(report_number); + +Table altered. + +SQL> desc ACCIDENT; + Name Null? Type + ----------------------------------------- -------- ---------------------------- + REPORT_NUMBER NOT NULL NUMBER(38) + ACCD_DATE DATE + LOCATION + +SQL> create table OWNS (driver_id# varchar(30),regno varchar(20),primary key(driver_id#,regno),constraint fkey1 foreign key(driver_id#)references PERSON (driver_id#),constraint fkey2 foreign key(regno)references CAR); + +Table created. + +SQL> desc OWNS + Name Null? Type + ----------------------------------------- -------- ---------------------------- + DRIVER_ID# NOT NULL VARCHAR2(30) + REGNO NOT NULL VARCHAR2(20) + +SQL> select table_name from user_tables; + +TABLE_NAME +-------------------------------------------------------------------------------- +ACCIDENT +CAR +OWNS +PERSON + +SQL> create table PARTICIPATED (driver_id# varchar(30), regno varchar(20), report_number int, damage_amount int, primary key(driver_id#,regno,report_number),constraint fkey1participated foreign key(driver_id#) references Person(driver_id#),constraint fkey2participated foreign key(regno) references car(regno),constraint fkey3paricipated foreign key(report_number) references accident); + +Table created. + +SQL> desc PARTICIPATED + Name Null? Type + ----------------------------------------- -------- ---------------------------- + DRIVER_ID# NOT NULL VARCHAR2(30) + REGNO NOT NULL VARCHAR2(20) + REPORT_NUMBER NOT NULL NUMBER(38) + DAMAGE_AMOUNT NUMBER(38) + +SQL> select * from person; + +DRIVER_ID# NAME +---------- -------------------------------------------------- +ADDRESS +-------------------------------------------------------------------------------- +1234 Rohan +Delhi India + + +SQL> alter table person modify driver_id# varchar (30); + +Table altered. + +SQL> insert into person values(1235,'Rohit','Banglalore India'); + +1 row created. + +SQL> insert into person values(1236,'Ramesh','Baharashtra India'); + +1 row created. + +SQL> insert into person values(1237,'Saarthak','Manipal India'); + +1 row created. + +SQL> desc person; + Name Null? Type + ----------------------------------------- -------- ---------------------------- + DRIVER_ID# NOT NULL VARCHAR2(30) + NAME VARCHAR2(50) + ADDRESS VARCHAR2(100) + +SQL> select * from person; + +DRIVER_ID# +------------------------------ +NAME +-------------------------------------------------- +ADDRESS +-------------------------------------------------------------------------------- +1234 +Rohan +Delhi India + +1235 +Rohit +Banglalore India + +DRIVER_ID# +------------------------------ +NAME +-------------------------------------------------- +ADDRESS +-------------------------------------------------------------------------------- + +1236 +Ramesh +Baharashtra India + +1237 +Saarthak + +DRIVER_ID# +------------------------------ +NAME +-------------------------------------------------- +ADDRESS +-------------------------------------------------------------------------------- +Manipal India +``` \ No newline at end of file