Saturday, May 7, 2022

Interview Questions: - (UNIX - 0)

UNIX: -

 

Q) How to get inode number of a file/directory?

Ans – $ ls –i <File/Directory_Name>

 

Q) What is inode?

Ans – inode number is unique identifier given to a file or directory inside a file system.

 

Q) What happens to inode when file is deleted?

Ans - When a file or directory is "deleted" its inode number is removed from the directory which contains the file.

 

Q) What action you will take if inode get filled?

Ans – If all inodes in a file system are completely filled, the unix system cannot create new files even when there is available space on the disk.

inode is full that means unix system have so many files which might be unnecessary. So just we have to find out those unnecessary files and delete them or  we have to find out hard links and removed it.

 

Q) How to find which Unix Operating system you are using?

Ans –$ uname –a

 

Q)  How to change group name of file/directory in unix?

Ans –  $ chgrp <group_name> <file/directory_name>

 

Q) How to change owner name of file or directory in unix?

Ans –  $ chown <owner_name> <file/directory_name>

 

Q) What is link and types of links and explain?

Ans –

 link is a pointer to an original file. It is of two types.

1.       Soft Link (Symbolic Link)

2.       Hard Link

SOFT LINK -

 It has below characteristics.

1.       It creates copy of original file.

2.       Both link file and original file have different inode number.

3.       Once original file is deleted, its corresponding soft link file is unusable.

4.       We can create soft link throughout the file system for the original file.

5.       You can create soft link to a directory.

Syntax: -

$ ln –s <Original File Name> <Soft Link File Name>

Example –

$ ln –s Sample.txt Sample.link

HARD LINK –

 It has below characteristics.

1.       It points to the inode number of the original file.

2.       Both link file and original file have same inode number.

3.       We can access the content of the link file as same as original file, once original file is deleted i.e. it is the backup of the original file.

4.       We can create hard link only within the file system, where original file is present.

5.       You cannot create hard link to a directory.

Syntax: -

$ ln <Original File Name> <Hard Link File Name>

Example –

$ ln Sample.txt Sample.link

Interview Questions: - (UNIX - 1)

UNIX: -

 

Q) Which command will show the output in screen and also saves the output in a file?

Ans – tee command

Example –

$ ls –lrt | tee f1<Enter – Key>

This Command will show the output of ls –lrt in the screen and saves the output in a file f1.

 

Q) What is zombie process?

Ans - When we send any request to shell, the shell calls a fork system call to create a child shell and assign that request to him. It is the responsibility of the child shell to complete the request and sends response back to parent shell. While sending back the response, if parent shell is not available to receive it, then it will keep the response in the result queue and die. Once the parent shell is available, it will search the result queue, take the response or result and display it. The time taken the child dies and parent shell gets the response, then the process will be in zombie state.

 

Q) What is orphan process?

Ans – If parent dies before child finishes it tasks, then the process is called as orphan process.

Here init is the parent process whose PID = 1.

 

Q) How much time unix system is up and running?

Ans - $ uptime

 

Q) What is 9 in kill command?

Ans - 9 is signal number in which kill command sends a signal with signal number 9 to kill the process.

  

Q) How to kill a process?

Ans –

$ ps –ef | grep <command_related_to_process>

Here you will get the process id i.e. 2nd column value.

$ kill -9 <PID_receive_from_1st_command>

 

Q) How you will see how much memory you directory and its sub directory are taking?

Ans - $ du –ch

 

Q) What are commands you are using in your project?

Ans –

ls –lrt

cat

touch

mv

cp

ps –ef

vi

sed

kill

sort

zip

gunzip

 

Q) How to create zero byte file in Unix?

Ans - $ touch <file_name>

Interview Questions: - (UNIX - 2)

UNIX: -

 

Q) Different methods to create a file?

Ans – vi

cat

touch

 

Q) What command will connect and transfer files in single line command?

Ans – scp command

scp source destination

Example –

scp /land01/path02/inbound/file34.dat username/password@servername:path

 

Q) How you know a server www.abc.com is up and running fine?

Ans - $ ping www.abc.com

If you will get output continuously, then it’s up and working fine otherwise not.

 

Q) How to create a tar file?

Ans - $ tar –cvf file.tar f1.txt f45.csv f2.dat<Enter – Key>

Where c – create

V – verbose mode

f - forcefull

 

Q) How to extract files from tar file or unzipped the tar file?

Ans - $ tar –xvf file.tar<Enter – Key>

Where x – extracts

V – verbose mode

f – forcefully

 

Q) How to delete a file from tar file?

Ans -  $ tar - - delete –f file.tar f1.txt<Enter – Key>

 

Q) How to append a file into tar file?

Ans - $ tar –rf file.tar f3.dat<Enter – Key>

Where r – append

 

Q) What is the use of tar ball ?

Ans – It helps in moving the files from one environment i.e. development or testing to another i.e. testing or production.

 

Q) How to zip a file and unzip a file?

Ans - $ zip file.zip f1.txt<Enter – Key>

Or

$ zip file23.zip f67.txt f45.dat fnv.png<Enter – Key>

$ unzip file.zip<Enter – Key>

 

Q) How to zip a file in its original location?

Ans - gzip f1.txt f2.csv f3.dat<Enter – Key>

$ gunzip f1.txt.gz f2.csv.gz f3.dat.gz<Enter – Key>

Interview Questions: - (UNIX - 3)

UNIX: -

 

Q) How to print lines without blank lines in a file?

Ans - $ grep –v ‘^$’ <file_name>

 

Q) Write a command to remove the first number on line 10 in file?

Ans - $ sed '10s/[0-9][0-9]*//' < filename

 

Q) Write a command to remove the first number on all lines that start with "@"?
Ans - $ sed '\,^@, s/[0-9][0-9]*//' < filename

 

Q) Write a command to replace the word "apple" with "(apple)" in a file?
Ans - $ sed s/apple/(&)/ < filename

 

Q) Write a command to replace the character '/' with ',' in a file?
Ans - $ sed 's/\//,/' < filename

 

Q) Write a command to see your current directory you are present in unix system?

Ans - $ pwd

pwd – Present Working Directory

 

Q) Which command will show the creation, modification and access time, inode number and number of links of a file?

Ans - $ stat <File Name>

 

Q) Whether the file file.sh is present in /var/logs/script directory or not ?

Ans - $ find /var/logs/script –type f –name file.sh

Whereas

–type f -> option search only files

-name -> option related to name of any files or directory

If you will get the file name in output, then file is present in the above directory otherwise not.

 

Q) Give me those files which are modified between 5-7 days in current directory?

Ans - $ find . –type f –mtime -7 –mtime +5

-mtime -> modified time option in days

-ctime -> creation time option in days

-7 -> within 7 days

+5 -> beyond or before 5 days.

 

Q) Find those files whose size is 12 GB in current directory?

Ans - $ find . –type f –size 20g

 

Q) Find those files whose size is more than 20 GB in current directory?

Ans - $ find . –type f –size +20g

 

Q) Find those files whose size is less than 20 GB in current directory?

Ans - $ find . –type f –size -20g

 

Q) Find all files whose permission is 644 and change it to 755 in current directory?

Ans - $ find . –type f –perm 644 –exec chmod 755 {} \;

 

Q) How to delete the temporary files in /tmp directory?

Ans - $ find /tmp –type f –name ‘*.tmp’ –exec rm –f {} \;

 

Q) Find all the files created before 6 months having ‘core’ word in the name of the file and remove it ?

Ans - $ find . –type f –ctime +180 –name ‘*core*’ –delete

Or

$ find . –type f –ctime +180 –name ‘*core*’ –exec rm –f {} \;

 

Q) Search all ‘log’ files in /log directory and give me those files having ‘error’ word in it?

Ans - $ find /log –type f –name ‘*.log’ –exec grep –l error {} \;

 

Q) Move all the files which are not modified within 6 months to /usr/archieve directory?

Ans - $ find . –type f –mtime +180 –exec mv {} /usr/archieve \;

Interview Questions: - (UNIX - 4)

UNIX: -

 

Q) How to create an empty directory?

Ans - $ mkdir <Directory_Name>

 

Q) How to create multiple directories in same level?

Ans - $ mkdir <1st Directory Name> <2nd Directory Name> <3rd Directory Name>

Example - $ mkdir d1 d2 d3 d4

 

Q) How to create multiple directories in hierarchical structure?

Ans - $ mkdir –p <1st Directory Name>/<2nd Directory Name>/<3rd Directory Name>

Example - $ mkdir –p d1/d2/d3/d4

 

Q) Why we go for Unix Operating Systems where window is a popular operating system?
Ans - These are the below points why we go for Unix Operating System.
1. Multi User, Multi Tasking
2. Crash Free
3. Virus Free


Q) Unix Architecture?
Ans -


SHELL - It is the interface between user and kernel. It receives the input from user, converts it

into kernel understandable codes and send to kernel.
KERNEL - It interacts with hardware, process the input received from shell and response back
to shell.
HARDWARE - It stores physical data as computer hardware.

 

Q) Why we go for shell scripting?

Ans – In Unix command prompt, we can run a single command at a time. To combine and run multiple commands for performing certain tasks, shell script is evolved.

Sunday, April 24, 2022

Interview Questions: - (SQL)

SQL: -

Q) How you take back up/copy of a table?

Ans – create table <backup_table_name> as select * from <table_which_to_be_back_up>;

 

Q) How to copy structure of a table?

Ans – create table <copied_table_name> as select * from <table_from_which_structure_copied> where 1=2;

 

Q)  What is self join with example?

Ans – Joining of a table happens with itself is called self join.

In this case, foreign key of a table refers to primary key of same table.

Example –

Select e.ename Employee_Name, m.ename Manager_Name from emp e, emp m

Where e.mgr = m.empno;

 

Q) What is equi  join with example?

Ans – Equi join between two tables return matching records from both table based upon common columns of both table.

Example –

Select e.ename, d.dname from emp e, dept d where e.deptno=d.deptno;

 

Q)  Difference between clustered index and non-clustered index?

Ans –

Clustered Index –

·         Clustered Index is a type of index that sort the data rows in a table on their key values.

·         Cluster Index doesn’t require additional disk space.

·         Cluster Index offers faster data accessing.

·         Clustered Index creates on Primary key column.

Non – Clustered Index –

·         Non - clustered Index is a type of index that stores the data rows at one location and indices at another location.

·         Non - cluster Index requires  additional disk space.

·         Non - cluster Index offers lesser data accessing speed than clustered index.

·         Non - clustered Index creates on unique column.

 

Q) What is difference between char and  varchar data types?

Ans –

Char – (Characters)

·         It stores maximum 2000 bytes of characters data.

·         Character data type is used to store strings of fixed length.

·         Char data type uses static memory location.

·         Char data type can be used when we expect the data values in a column to be of same length.

Varchar – (Variable Characters)

·         It also stores maximum 2000 bytes of characters data.

·         Varchar data type is used to store strings of variable length.

·         Varchar  data type uses dynamic memory location.

·         Varchar data type can be used when we expect the data values in a column to be of variable length.

 

Q) What is difference between varchar and varchar2?

Ans –

Varchar –

·         It stores maximum 2000 bytes of characters data.

·         Varchar can identify NULL and empty string separately.

·         Varchar is ANSI SQL Standard.

Varchar2 –

·         It stores maximum 4000 bytes of characters data.

·         Varchar2 can identify NULL and empty string same.

·         Varchar2 is Oracle Standard.

 

Q) Write a SQL query to find sum of positive and negative values from a column in separate columns for a table?

Ans –

select accountid,

   sum(case when amount>0 then amount else 0 end) as Positive_Value,

   sum(case when amount<0 then amount else 0 end) as Negative_Value

   from account_master

   group by accountid;

Here accountid and amount are two columns of account_master table.

amount column has some positive and negative values.

 

Q) What is version of Oracle you are using?

Ans – Oracle 10g

 

Q) How to find version of Oracle database you are using?

Ans – select * from v$version;

 

Q) Could you please tell me which is better sub query or join?

Ans – Join is better than sub query as join helps query optimization and faster data retrieval time than subquery.

 

Q) What s NVL and NVL2 function and difference?

Ans – NVL converts null value to actual value where as NVL2 converts both null and not null values to actual Values.

NVL(COMM,0) -> If comm is null, then it converts that null value to 0.

NVL2(COMM,COMM+100,100) -> if comm is null, then NVL2 converts that null value to 100, and if it is not null, then comm is comm.+100.

 

Q) If a job is running long or any database query is long running, then what action you are taking?

Ans –

If a job is running long or any database query is long running, then we have to escalate the issue with database team.

DBA has to fix the issue by adding hints in view or rebuilding indexes or optimize the query.

 

Q) What is table space and how to find out?

Ans –

The table space is where tables get stored.

It links the physical storage layer (files on disks) and the logical storage layer (tables, indexes).

Query – (to get table space name)

select tablespace_name from all_tables where owner = 'SCOTT' and table_name = 'EMP';

 

Q) What is lock and deadlock?

Ans –

Lock occurs when one process accesses a piece of data where there is a chance that another concurrent process will need this piece of data as well at the same time. By locking the piece of data we ensure that we are able to action on that data the way we expect.

Deadlock occurs when one process is blocked and waiting for a second process to complete its work and release locks, while the second process at the same time is blocked and waiting for the first process to release the lock.

 

Q) What is the use of where clause and having clause?

Ans –

·         WHERE is used to filter rows before grouping, and HAVING is used to exclude records after grouping.

·         Where clause is used before group by clause and action on non aggregate columns.

·         Having clause is used after group by clause and actions on aggregate function.

 

Q) One SQL Query runs usually 5 mins, but today it ran more than 15 mins why?

Ans –

Might be we have received more records in the file from source than normal days.

If it’s again long running, then we have to escalate the issue with database team. 

 

Q) A code is developed by developer in DEV environment and its working fine in DEV environment.

If you will push the code in Production environment, then there might be failure which impact users as well as production. What action you will take?

Ans – Before moving a code into production, it should be test in similar PROD environment like UAT  environment and if successful, then move it to production and if its fail in UAT environment, then Dev team will fix it.

 

Q) What is DR activity?

Ans - Disaster recovery is an organization's method of regaining access and functionality to its IT infrastructure after events like a natural disaster, cyber attack, or even business disruptions related to the COVID-19 pandemic.

 

Q) What is incident and Problem?

Ans –

Any interruption to normal process is called incident.

If the incident happens frequently, then it called problem and then we have to involve different teams to fix the issue permanently.

Friday, April 15, 2022

 Interview Questions:  - (SQL)

SQL :  -

Q) To print nth highest sal?

Ans - Select * from (select a.*,dense_rank() over (order by sal desc) r  from emp a) where r=n;

Here n means the number which you want to select highest salary

Ex: r=2 for second highest salary

 

Q)  To print nth lowest sal?

Ans - Select  *  from (select a *,dense_rank() over(order by sal asc) r from emp a) where r=n;

Here 'n' means the number which you want to select lowest salary

Ex: r=5 for fifth lowest salary

 

Q)  To print top 3 highest sal?

Ans - Select  *  from (select a.*,dense_rank() over (order by sal desc) r  from emp a) where r <= 3;

 

Q)  To print top 4 lowest sal?

Ans - Select  *  from (select a.*,dense_rank() over(order by sal asc) r  from emp a) where r <= 4;

 

Q) To print only 5th highest sal?

Ans - Select  *  from (select  a.*,dense_rank() over(order by sal desc) r  from emp a) where r=5;

 

Q)  To print first and last record in a table?

Ans –

-- the below query is for only first record

Select * from emp where rowid=(select min(rowid) from emp);

--the below query is for only last record

Select * from emp where rowid=(select max(rowid) from emp);

 

Q)  To print even records?

Ans – Select  *  from (select rownum r,emp.*  from emp) where mod(r,2)=0;

 

Q)  To print odd records?

Ans - Select * from (select rownum r,emp.* from emp) where mod(r,2)=1;

 

Q) To find all tables with their number of rows in a schema?

Ans - Select table_name,num_rows from user_tables;

 

Q)  To find number of columns for specific table in a schema?

Ans - Select count(*) from user_tab_columns where table_name='emp';

 

Q) To insert same data from one table to another  table?

(Provided that columns name and number will be same in both tables)

Ans - Insert into emp select * from account_owner;

 

Q) To print duplicate records?

Ans – select  * from emp where rowid not in (select max(rowid) from emp group by empno);

 

Q) To delete duplicate records?

Ans - delete from emp where rowid not in (select max(rowid) from emp group by empno);

 

Q) How to get 10th record from a table?

Ans – Select  *  from emp where rownum<11 minus select * from emp where rownum<10;

 

Q) How to get 18th record from a table?

Ans – Select  *  from emp where rownum<19 minus select  *  from emp where rownum<18;

 

Q) To print 1 to 100 numbers sequentially?

Ans - Select  level  from dual connect by level <=100;

 

Q) Write a query to print the name which is more than one time and number of rows present in the table for that name?

Ans –

select ename, count(*) from emp

group by ename

having count(*) > 1;

 

Q) Write a query to print the salary amount which is more than three times and number of times present in the table?

Ans –

select  sal, count(*) from emp

group by sal

having count(*) > 3;

 

Q) What is dual table?

Ans –

dual is a dummy table.

Owner of the table is system.

It has one row and one column.

 

Q) Write a query to print your name one time?

Ans – select “Baishnab Charan Patra” from dual;

 

Q) Write a query to find sum of 145 and 55?

Ans – select  145 + 55 from dual;

 

Q) Difference between delete, truncate, and drop?

Ans –

Delete:  -

It is DML statement.

It is not auto commit.

It deletes one record or entire record or multiple records from the table.

It is less faster  than truncate.

DBA can rollback the data after delete statement.

Truncate :  -

It is DDL statement.

It is auto commit.

It deletes entire record from table.

It is faster than delete.

We cannot rollback data after truncate.

Drop :  -

It is DDL command.

It delete both record and structure of the table from the database.

1.       To rollback the table, we can use,

Flashback table table_name before drop;

2.       To delete complete the table from database, we can use,

Purge table table_name;

 

Q) Why delete is less faster than truncate?

Ans – delete scans one record at one time from table and delete it, where as truncate doesn’t scan every record before removing it. Truncate takes less transaction space than delete.

 

Q) What is the difference between Union and Unionall?

Ans –

Unionall selects all values from both tables without removing duplicates, whereas union selects all unique values from both tables.

TableA:  -

Name- (Coulmn)

Hiranya

Baishnab

Ram

TableB: -

Name –  (Column)

Hiranya

Baishnab

John

Results:  -

Unionall –

Name –

Hiranya

Baishnab

Ram

Hiranya

Baishnab

John

Union –

Name –

Hiranya

Baishnab

Ram

John

 

Q)  What is index and types of index?

Ans –

Index is a schema object which is used to improve performance of data retrieval.

Index will improve performance of select, update and delete queries.

Indexes are created on columns.

Syntax –

Create index index_name on table_name (column_name);

Types –

1.       Simple Index – index created on one column

Syntax –

Create index index_name on table_name (column_name);

2.       Composite Index – index created on more than one columns

Syntax –

Create index index_name on table_name (column_name1, column_name2);

3.       Unique Index – unique index doesn’t allow duplicate values on the column on which its created. Index won’t create on primary key column as system creates a unique index automatically on this column.

Syntax –

Create unique index index_name on table_name (column_name);

4.       Bitmap index – indexes created on low cardinality columns.

Syntax –

Create bitmap index index_name on table_name (column_name);

5.       Function based index – indexes created on function.

Syntax –

Create index index_name on table_name (function_name(column_name));

 

Q) What is view and types of view?

Ans –

View is a virtual table and its doesn’t occupy space in database.

The query associated in the view will be stored in the database, not the results so its called stored query.

Its help us in security and simplicity.

Syntax –

Create view view_name

as

select column_names from table_names

where condition

with check option

with ready only;

Example –

Create view v1 as select empno,ename,job,sal from emp where job = ‘CLERK’  with check option;

insert into v1 values (234,’AMP’,’MANAGER’4000);

ERROR

As its allow only JOB = ‘CLERK’, but we are inserting job = ‘MANAGER’ so violates.

If a view is created with ready only option, then no DML operations would allow.

 

Q) Difference between simple and complex view?

Ans –

Simple View –

View should create on one table.

It is updatable.

DML operation is allowed.

Example –

Create view v4 as select ename,empno,sal,job from emp where job = ‘CLERK’;

Complex View –

View should create on more than one table.

It is not updatable.

DML operation is not allowed.

Example –

Create view v2 as select empno,ename,dname from emp, dept where emp.deptno=dept.deptno;

 

Q) What is materialized view?

Ans –

Materialized view is physical table which stores query as well as results in database.

Example –

Create materialized view mv1 as select deptno,sum(sal) from emp gropu by deptno;

Refresh –

Execute dbms_mviews.refresh (mv1);

 

Q) Difference between view and materialized view?

Ans –

BASIS FOR COMPARISON

VIEW

MATERIALIZED VIEW

Basic

A View is never stored it is only displayed.

A Materialized View is stored on the disk.

Define

View is the virtual table formed from one or more base tables or views.

Materialized view is a physical copy of the base table.

Update

View is updated each time the virtual table (View) is used.

Materialized View has to be updated manually or using triggers.

Speed

Slow processing.

Fast processing.

Memory usage

View do not require memory space.

Materialized View utilizes memory space.

 

Q) Difference between rank and dense_rank?

Ans –

RANK will skip the next available ranking value whereas DENSE_RANK would still use the next ranking value.

RANK –

SAL:  -    RANK : -

1000       1

2000       2

3000       3

3000   3

4000   5

5000   6

5000   6

5000   6

6000   9

DENSE RANK –

SAL:  -    DENSE RANK : -

1000       1

2000       2

3000       3

3000       3

4000       4

5000       5

5000       5

5000       5

6000      6

 

Q) Difference between rowid and rownum?

Ans – rowid is static value for each row, where as row num is dynamic value from each row.

Rowid helps us to get a particular row from the table, where row num doesn’t help us to get particular row from table.

Both are pseudo columns.

 

Q) How to find 1st day of current month?

Ans – select add_month(last_day(sysdate) + 1,-1) from dual;

 

Q) Write a query to print those names which contains 3 M in his/her name?

Ans – select ename from emp where length(ename) – length(replace(ename,M,’’)) = 3;

 

Q) Write a query to print those names who are getting highest salary in their respective departments?

Ans –

Select ename from emp where (deptno,sal) in (select deptno,max(sal) from emp group by deptno);

 

Q) Write a query to print those names which name start with S? (two ways)

Ans –

Select  * from emp where  substr(ename,1,1) = ‘S’;

or

Select * from emp where ename like ‘S%’;

 

Q) What are types of constraints?

Ans –

1.       Unique

2.       not null

3.       primary key

4.       check

5.       foreign key

6.       default

 

Q) Difference between primary key and foreign key?

Ans –

Primary Key –

It allows unique values without duplicate and null.

Foreign key –

It points to primary key of different table or same table.

It holds all values along with null and the values should be part of primary key values.

 

A table has one primary key and multiple foreign keys.

 

Q) Difference between primary key, unique and not null?

Ans –

Unique –

Unique constraint holds unique values with null.

Not null –

Not null constraint holds all values without null.

 

Q) Difference between left outer join and right outer join?

Ans –

Left outer join –

It compares both tables and returns matching records from both tables and non matching records from left table based on common column of both tables.

Right outer join -

It compares both tables and returns matching records from both tables and non matching records from right table based on common column of both tables.

 

Q) What is equi/inner join and outer join?

Ans –

Equi Join –

It compares both tables and returns matching records from both table based on common column of both tables.

Outer Join –

It compares both tables and returns both matching and non matching records from both table based on common column of both tables.

 

Q) Write a query to print your name 9 times?

Ans –

Select repeat ("Baishnab Charan Patra", 9);

Example –

Select repeat (ename,3) from emp;

 

Q) Display 1st Friday of current month?

Ans – select next_day(add_month(last_day(sysdate) + 1,-1),’FRIDAY’) from dual;


Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...