Wednesday, 28 September 2016

Top Useful Network Monitoring Commands

Useful commands for network monitoring

Ping  (Unix/Windows)
Traceroute  (Unix/Windows)
Arp (Unix/Windows)
Curl and wget (Unix/ Windows)
Netstat (Unix/Windows)
Whois (Unix/ Windows)
SSH (Unix/Linux/Windows)
TCPDump (Unix/Linux/Windows)
Ngrep (Unix/Linux/Windows)
NMAP (Unix/Windows)
Netcat (Windows/Unix)
Lsof (Unix/Windows)
IPtraf (Linux)

Ping (Unix/Window):
Ping is very basic and important command. Ping sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds, you get an ICMP packet back. You can “ping” an IP address to see if a machine is alive. If there is no response, you know something is wrong. It’s also used to check the “speed” or latency time for said network connection. It’s a command that exists on all OS’s that support TCP/IP and it’s one of those basics you should know. Following is the ping examle.

$ ping HostName/IP Address
$ ping google.com
$ ping 192.168.182.132

You can specify the count of ECHO_REQUEST packets to be sent while ping a host. For this we can use parameter '-c' as following.

$ ping -c 4 192.168.182.132
PING 192.168.182.132 (192.168.182.132) 56(84) bytes of data.
64 bytes from 192.168.182.132: icmp_req=1 ttl=64 time=0.281 ms
64 bytes from 192.168.182.132: icmp_req=2 ttl=64 time=0.495 ms
64 bytes from 192.168.182.132: icmp_req=3 ttl=64 time=0.459 ms
64 bytes from 192.168.182.132: icmp_req=4 ttl=64 time=0.250 ms

--- 192.168.182.132 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.250/0.371/0.495/0.107 ms

Traceroute  (Unix/Windows):
Traceroute command is a very useful network diagnostic tool. Traceroute displays each host that a packet travels through(devices, switches, routers, computers) as it tries to reach its destination. In case of trouble it can give us an idea at which point problem is there while moving packets to its destination.

Traceroute (Unix):
~$ traceroute 192.168.182.132
traceroute to 192.168.182.132 (192.168.182.132), 30 hops max, 60 byte packets
 1  ubuntu.local (192.168.182.132)  0.302 ms  0.316 ms  0.304 ms

tracert( Window ):
C:\Users\Mukesh.Kumar>tracert google.com

Tracing route to google.com [216.58.220.46]
over a maximum of 30 hops:
  1     *        *        *     Request timed out.
  2    48 ms    56 ms    49 ms  10.210.0.82
  3    55 ms    23 ms    41 ms  10.210.0.86
  4    25 ms    26 ms    29 ms  125.17.150.37
  5    62 ms    42 ms    38 ms  182.79.234.221
  6    49 ms     *       59 ms  72.14.242.178
  7    56 ms    46 ms    34 ms  66.249.94.73
  8    44 ms    36 ms     *     209.85.255.43
  9    57 ms    50 ms    29 ms  maa03s18-in-f14.1e100.net [216.58.220.46]

Trace complete.

Note : The Unix "traceroute" uses UDP datagrams rather than ICMP to perform a similar function link ping.

Arp (Unix/Windows) :
Using the arp command allows you to display and modify the Address Resolution Protocol (ARP) cache. An ARP cache is a simple mapping of IP addresses to MAC addresses.
Example:
C:\Users\Mukesh.Kumar>arp -a 192.168.182.132

Interface: 192.168.182.1 --- 0x1e
  Internet Address      Physical Address      Type
  192.168.182.132       00-0c-29-08-b7-93     dynamic
 
Wget and curl (Unix/ Windows):
    This command allow to download files or entire webpage.both are command line tools that can download contents from FTP, HTTP and HTTPS
    both can send HTTP POST requests
    both support HTTP cookies
    both are designed to work without user interaction, like from within scripts
    both are fully open source and free software
    both support metalink

    Note : curl supports FTP, FTPS, Gopher, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT,
      LDAP, LDAPS, FILE, POP3, IMAP, SMB/CIFS, SMTP, RTMP and RTSP.    
      Wget only supports HTTP, HTTPS and FTP

Netstat (Unix/Windows):
Netstat prints information about the Linux networking subsystem. By default, netstat displays a list of open sockets.  If you don't specify any address families, then the active sockets of  all  configured address families will be printed.  The type of information printed is controlled by the first argument,as follows:
Netstat( Unix ):
   --route , -r
       Display the kernel routing tables. See the description in route(8) for details.  netstat -r and route -e produce the same output.

   --groups , -g
       Display multicast group membership information for IPv4 and IPv6.

   --interfaces, -i
       Display a table of all network interfaces.

   --masquerade , -M
       Display a list of masqueraded connections.

   --statistics , -s
       Display summary statistics for each protocol.
'

Whois (Unix/ Windows) :
Network command used to consult domain data. Mainly data like the domain owner, it’s expire time, configured registries, contact data, etc. are consulted. It’s very recommendable to use it to contact domain administrators or for service migration instances, such as email or webpage migrations.

In order to use ‘whois’ on Windows, you should download the software linked on the following URL: https://technet.microsoft.com/en-us/sysinternals/whois.aspx

You can also consult them using services such as https://www.whois.net/ on your browser.

SSH (Unix/Linux/Windows):
SSH, or Secure Shell, is a protocol used to securely log onto remote systems. It is the most common way to access remote Linux and Unix-like servers.

$ ssh remote-host

If remote user name is diffrence then you can use username also
$ ssh user-name@remote-host

If you wish to execute a command on remote system, you can specify it after the host-name.
$ ssh remote_host command_to_run
$ ssh mukesh@ubuntu-server.com ls

Note : To use SSH on Windows we recommend using Putty. http://www.putty.org/

TCPDump (Unix/Linux/Windows):
tcpdump is a most powerful and widely used command-line packets sniffer or package analyzer tool which is used to capture or filter TCP/IP packets that received or transferred over a network on a specific interface. It is available under most of the Linux/Unix based operating systems. tcpdump also gives us a option to save captured packets in a file for future analysis. It saves the file in a pcap format, that can be viewed by tcpdump command or a open source GUI based tool called Wireshark (Network Protocol Analyzier) that reads tcpdump pcap format files.

Ngrep (Unix/Linux/Windows):
This takes the potency of the ‘grep’ command to the Net. It’s basically a tcpdump with text subchain filters in real time. It’s an HTTP, SMTP, DNS and other protocol communication packets filter. It has a very powerful filtering system over regular expressions and it’s usually used to process files generated by tcpdump, Wireshark, etc.

NMAP (Unix/Windows):
The Nmap aka Network Mapper is an open source and a very versatile tool for Linux system/network administrators. Nmap is used for exploring networks, perform security scans, network audit and finding open ports on remote machine. It scans for Live hosts, Operating systems, packet filters and open ports running on remote hosts.

Netcat (Windows/Unix):
Netcat or nc is a networking utility for debugging and investigating the network.

This utility can be used for creating TCP/UDP connections and investigating them. The biggest use of this utility is in the scripts where we need to deal with TCP/UDP sockets.

Lsof (Unix/Windows):
It’s a tool that’s useful for identifying which files a process is using or keeping open. In the case of Unix environments, a file is also a network connection, so it’s useful to know which ports are open during a specific running process, something which can prove to be extremely useful in some cases.
It can also be used to know how many files a single process has open. It doesn’t have anything to do with the network, but we’re sure it’ll be useful for you anyway. Lsof is one of those tools you should know about.

IPtraf (Linux):
A specialized network command which obtains traffic statistics. It has an ncurses interface (text) to analyze the traffic that goes through an interface in real time. Very useful if you see anomalies on your device and you need to see and inspect the traffic coming through it.

Sunday, 25 September 2016

How To Install NRPE on Ubuntu 16.04, 14.04, 12.04 and LinuxMint

NRPE is stands for Nagios Remote Plugin Executor. In previous post i had described about installation of Nagios Server on Ubuntu operating system(link). This article will help you to install NRPE on Ubuntu 15.04, 14.04, 12.04 & LinuxMint systems.

The NRPE addon is designed to allow you to execute Nagios plugins on remote Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor "local" resources (like CPU load, memory usage, etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines.
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

Note: It is possible to execute Nagios plugins on remote Linux/Unix machines through SSH. There is a check_by_ssh plugin that allows you to do this. Using SSH is more secure than the NRPE addon, but it also imposes a larger (CPU) overhead on both the monitoring and remote machines. This can become an issue when you start monitoring hundreds or thousands of machines. It is useful to use NRPE to lower load on monitoring and remote host as well.












 As showing in above image the NRPE addon consists of two pieces:

– The check_nrpe plugin, which resides on the local monitoring machine.
– The NRPE daemon, which runs on the remote Linux/Unix machine.

Step 1. Install NRPE and Nagios Plugins

NRPE is available under default apt repositories of Ubuntu systems. Execute the following command to install it

$ sudo apt-get install nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standard

Step 2. Configure NRPE

Edit the /etc/nagios/nrpe.cfg file and in allowed_hosts give the ip address of Nagios monitoring Server from which monitoring will be done. For example nagios monitoring host server ip is 192.168.182.130, then add this IP address to allowed_hosts list.

allowed_hosts=127.0.0.1,192.168.182.130

Step 3. Restart the NRPE service

Restart the nrpe service in client machine with following command.

$ sudo /etc/init.d/nagios-nrpe-server restart
Step 4. Install nagios-nrpe-plugin package in your nagios monitoring server. 
Run the following command to install the check_nrpe plugin on your Nagios server. It will install check_nrpe plugin under /usr/lib/nagios/plugins/.

$ sudo apt-get install nagios-nrpe-plugin

Step 5. Verification 

Now login to the nagios server and sudo nagios user. To verify if nagios are able to communicate with nrpe agent in client machine run check_nrpe plugin by passing client machine IP address ( In my case client machine IP is 192.168.182.131 )as following. If you are not able to find check_nrpe plugin please follow the setp 4 to install check_nrpe plugin.

nagios@ubuntu:~$ /usr/lib/nagios/plugins/check_nrpe -H 192.168.182.131
NRPE v2.12

The output "NRPE v2.12" shows that the nagios server was successfully communicating with NRPE agent.

Step 6. Add nagios check command in NRPE

By defaults all nagios installed in /usr/lib/nagios/plugins/ directory. You can add new service check as per your requirements in /etc/nagios/nrpe.cfg. Folloing are the default check commans in nrpe.cfg file.

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

Step 7. Start/Stop/Restart NRPE service

Each time when we make change into the configuration file which are in client machine that time we need to restart the nrpe srevice.

$ sudo /etc/init.d/nagios-nrpe-server stop
$ sudo /etc/init.d/nagios-nrpe-server start
$ sudo /etc/init.d/nagios-nrpe-server restart


   
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

Tuesday, 30 August 2016

SQL Important Queries

>I have a table with duplicate items in it. Write me a query which returns only duplicate rows with number of times they are repeating.

    select item,count(*) from tab group by item having count(*)>1;

>How to find the 2nd max sal from the table.

  To get 2nd highest salary.
  select max(salary) from employee where salary < (select max(salary) from employee);
  select max(salary) from employee where salary not in(select max(salary) from employee);

  To get 5th highest salary.
  select * from tab a where 5 =(select count(distinct salary) from tab b where a.salary<=b.salary);
 
> What command is used to create a table by copying the structure of another table?
   without data:
   CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1=2;

   with data:
   CREATE TABLE new_table AS SELECT * FROM old_table ;

> How to copy all data from tab1 to tab2 ,where tab1 and tab2 having same table structure.

   INSERT INTO emp_details1 SELECT * from emp_details where emp_id >1000;

> What operator tests column for the absence of data?
    NULL operator is used to check the absence of data in a column.
    Example:
    SELECT * FROM emp WHERE sal is NULL;
  
> How can we delete records in a table using update table?
  update tab set name=null where id=2;
 
>Identify error in following SQL:
    SELECT EMPNO, SUM(SAL)
    FROM EMP
    GROUP BY EMPNO
    HAVING ENAME= ?KENT?
a) Syntax Error
b) SUM() is not an aggregate function
c) HAVING can not be used with GROUP BY
d) The Having condition has to be based on some column that appears in the select list.
 
>How to remove the duplicate records from table which havting same id? Consider following table which having 2 rows with id=100.
  #select * from tab;
     id  |    name    |
    -----+------------+
     100 | mukesh     |
     101 | shivam     |
     102 | smrati     |
     100 | mukesh     |
     --in above table need to remove mukesh
--step1
  add one column num
  --ALTER TABLE tab2 ADD column num character varying;
--Step2
  Create sequence num_seq;
--Step3
  UPDATE TABLE tab set num=nextval('num_seq');
--Step4
  DELETE FROM tab where num in(SELECT MAX(num) from tab group by name having count(*)>1;
--Step5
  Check if still duplicate is there.
  Select count(*),name from tab group by name having count(*)>1;
  if above query returns any records ,repete step4.
 
 --Method 2 :

      acc_no |  name  | joint_account
    --------+--------+---------------
     100    | mukesh | 101
     200    | shivam | 102
     300    | smrati | 200
     400    | rity   | 100
     100    | mukesh | 122
     401    | rity   | 122
     402    | rity   | 122
  
--delete from emp_details1 where acc_no not in(select min(acc_no)from emp_details1 group by name);

    mydb=# select * from emp_details1;
     acc_no |  name  | joint_account
    --------+--------+---------------
     100    | mukesh | 101
     200    | shivam | 102
     300    | smrati | 200
     400    | rity   | 100
     100    | mukesh | 122

SQL Theory Questions & Answers

> How many kinds of statement SQL have?

SQL have 3 kind of statements as following.
DDL (Data Definition Language)
    CREATE – To create objects in the database
    ALTER  – To alter the structure of the database
    DROP   – To delete objects from the database
    TRUNCATE – To remove all records from a table. The  space allocated for the records is also removed

DML (Data Manipulation Language):
    SELECT – To retrieve data from the database
    INSERT – To insert data into a table
    UPDATE – To update existing data within a table
    DELETE – To delete all records from a table. Delete statement does not release space.

DCL (Data Control Language ):
    GRANT     – To give user access privileges to database objects
    REVOKE  – To withdraw access privileges given with the GRANT command
    COMMIT  – To save the work done
    ROLLBACK – To restore database to original since the last COMMIT

> How many types of constraints are in SQL ?

Constraints are the rule that restricts the values in a database.
  1.   PRIMARY KEY
  2.   NOT NULL
  3.   UNIQUE
  4.   CHECK
  5.   FOREIGN KEY
> What is the difference between primary key and unique key?
 
Primary Key:
i  ) Can be only one in a table.
ii ) It never allows null values.
iii) Primary Key is unique key identifier and can not be null and must be unique.

Unique Key:
i  ) Can be more than one unique key in one table.
ii ) Unique key can have one or multiple null but value can not duplicate.
iii) It can’t be candidate key
iv ) Unique key can be null and may not be unique.
 
> What is the difference between TRUNCATE and DELETE commands?
  •   DELETE is a DML command whereas TRUNCATE is a DDL command.Hence DELETE operation can be rolled back but TRUNCATE can not.
  •   DELETE does not release the memory occupied by the records of the table .TRUNCATE releases the memory occupied by the records of the table
  •   WHERE clause can be used with DELETE and not with TRUNCATE.
> Explain UNION, MINUS, UNION ALL and INTERSECT?

    INTERSECT - Return all distinct rows but conman records exist in both queries.
    Union     - Return all distinct rows from both queries.
    Union All - Returns all rows of both queries.
    MINUS     - Returns all distinct rows selected by the first query but not by the second

Example:
SELECT new_id from tab1 INTERSECT SELECT new_id FROM TAB2;

> How many types of join explain with example.
1) Cartesian join
2) Inner join
3) Outer join
    -Left-outer join
    -Right-outer join
4) Self join

1) Cartesian join:
    A Cartesian join occurs when data is selected from two or more tables and there is no common relation specified in the WHERE clause.
    If the first table has 3 rows and the second table has 4 rows, the result will have 12 rows.
    Example:
    SELECT * FROM Table1,Table2;
  
2) Inner join:
    Inner join is the cartesian product between 2 or more tables which satisfies the join condition in the WHERE clause .
    Example:
    SELECT Table1.Emp_ID, Table1.City, Table2.Cust_ID, Table2.City
    FROM Table1, Table2
        WHERE Table1.City = Table2.City;

3) Outer join
    -Left-outer join :
    A left outer join will return all the rows that an inner join returns and also return those rows from left table which does not have match in right side table.

    -Right-outer join
    A right outer join will return all the rows that an inner join returns and also return those rows from right table which does not have match in lest side table.

4) Self join:
    When you wish to join a table with itself based on some criteria then treat the table as two different tables by giving synonyms.
    Example:
    Consider a table Employee_Manager with column Emp_id,Emp_name and Mgr_id
    SELECT     Emp.Employee_ID , Emp.Employee_Name ,
    Emp.Mgr_id , Manager.Employee_Name
     FROM employee_Manager  Emp, employee_Manager  Manager
        WHERE Emp.Mgr_id  =  Manager.Employee_ID;
      
> What is difference between Stored Procedure and Trigger?
  • For executing SP(Stored Procedure) we have to call Stored Procedure. But in case of Trigger it is call whenever there is an action takenon table or column(Insert, Update ,Delete).
  • Stored procedure can take input parameters, but we can not pass parameters as input to a trigger.
  • Stored procedure returns value but trigger cannot returns value.
  • Stored procedures can be scheduled through a job to execute on a predefined time, but we can not schedule a trigger.
  • We can use Print commands inside a stored procedure for debugging purposes but we can not use print commands inside a trigger.
  • Stored procedures are used for performing tasks while Triggers used for auditing work.
> What is difference between procedure and function?
  • Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
  • Functions can have only input parameters for it whereas Procedures can have input/output parameters .
  • Functions can be called from Procedure whereas Procedures cannot be called from Function.
> How to add constraints while creating table
  CREATE TABLE Customer1(
    customerid varchar2(4) CONSTRAINT cust1_pkey PRIMARY KEY CHECK (customerid like 'C%'),
    customername varchar2(20) CONSTRAINT custname_nnull NOT NULL,-- DEFAULT 'XXX',
    emailid varchar2(20) CONSTRAINT email_unique UNIQUE,
    accountno NUMBER CONSTRAINT acc_fkey REFERENCES accounts(accno)
);

--MySQL DB
CREATE TABLE `staging`.`DailyCheck` (
   `date` date NOT NULL DEFAULT '0000-00-00',
   `campaignid` varchar(255) NOT NULL DEFAULT '',
   `campaign` varchar(255) NOT NULL,
   `imps` int(11) NOT NULL DEFAULT '0',
   `clicks` int(11) NOT NULL DEFAULT '0',
   `cost` double NOT NULL DEFAULT '0',
   PRIMARY KEY (`campaignid`,`date`),
   KEY `datidx` (`date`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 CREATE TABLE CUSTOMER(
    customerid varchar(4) NOT NULL,
    customername varchar(20) NOT NULL,-- DEFAULT 'XXX',
    emailid varchar(20)  UNIQUE,
    accountno int(11)
    );
  
> How to use AAD,DROP and MODIFY on column.
    DROP TABLE TAB1;

    ALTER TABLE tab ADD phone_no char(10);
    ALTER TABLE tab MODIFY phone_no char(12); --not working in postgres.
    ALTER TABLE tab1 MODIFY phone_no CONSTRAINT ph_nnull NOT NULL;
    ALTER TABLE tab ADD CONSTRAINT tab_uniqe UNIQUE(phone_no);

--modifying column in postgresql
    ALTER TABLE "MY_TABLE" ALTER COLUMN "MyColumn" TYPE varchar(8) USING substr("MyColumn", 1, 8)

    ALTER TABLE tab DROP CONSTRAINT ph_unique;
--droping a column
    ALTER TABLE TAB DROP column phone_no;
--rename a column
    ALTER TABLE TAB1 RENAME COLUMN id to new_id;

    ALTER TABLE TAB ADD CONSTRAINT tab_pkey PRIMARY KEY (ID);
    alter TABLE tab add CONSTRAINT tab_pkey PRIMARY KEY (ID,NAME);
    ALTER TABLE TAB ADD CONSTRAINTS c_check CHECK(ID BETWEEN 101 AND 120);

    ALTER TABLE tab DROP constraint tab_pkey;
    ALTER TABLE TAB DROP PRIMARY KEY; --Not supporting in postgres

    ALTER TABLE employee ADD FOREIGN KEY (dno) REFERENCES department(dnumber)

> In subqueries, which is efficient ,the IN clause or EXISTS clause? Does they produce the same result?

  EXISTS is efficient because,
  1.Exists is faster than IN clause.
  2.IN check returns values to main query where as EXISTS returns Boolean (T or F).
 
> Explain normalization with examples.

Normalization is a process of eleminating the redundancy and increasing the integrity.
Normal Forms: Review : -
Unnormalized ? There are multivalued attributes or repeating groups
    1 NF ? No multivalued attributes or repeating groups.
    2 NF ? 1 NF plus no partial dependencies
    3 NF ? 2 NF plus no transitive dependencies

Option 1: Make a determinant of the repeating group (or the multivalued attribute) a part of the primary key.

Option 2: Remove the entire repeating group from the relation. Create another relation which would contain all the attributes of the repeating group, plus the primary key from the first relation. In this new relation, the primary key from the original relation and the determinant of the repeating group will comprise a primary key.

Remove the attributes, which are dependent on a non-key attribute, from the original relation. For each transitive dependency, create a new relation with the non-key attribute which is a determinant in the transitive dependency as a primary key, and the dependent non-key attribute as a dependent.
        
> What is De-normalization and difference between normalization and De-normalization?
  • De-normalization is the process of attempting to optimize the performance of a database by adding redundant data or by grouping data.
  • Normalization is the process of De-composing a relation with anomalies into a well structured relation.
> What is difference between Co-related sub query and nested sub query?
  •   Correlated sub query runs once for each row selected by the outer query. It contains a reference to a value from the row selected by the outer query.
  •   Nested sub query runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.
  For example,
  Correlated Subquery:
    select e1.empname, e1.basicsal, e1.deptno from emp e1 where e1.basicsal = (select max(basicsal) from emp e2 where e2.deptno = e1.deptno);

  Nested Subquery:
    select empname, basicsal, deptno from emp where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by deptno);
  
> What is the main difference between the IN and EXISTS clause in sub queries?
The main difference between the IN and EXISTS predicate in subquery is the way in which the query gets executed.

IN : The inner query is executed first and the list of values obtained as its result is used by the outer query.The inner query is executed for only once.

EXISTS : The first row from the outer query is selected ,then the inner query is executed and , the outer query output uses this result for checking.This process of inner query execution repeats as many no.of times as there are outer query rows. That is, if there are ten rows that can result from outer query, the inner query is executed that many no.of times.

> what is the ACID property in database. 
ATOMICITY-- Atomicity requires that each transaction is "all or nothing": if one part of the transaction fails, the entire transaction fails, and the database state is left unchanged
CONSISTENCY -- The consistency property ensures that any transaction will bring the database from one valid state to another
ISOLATION -- Isolation refers to the requirement that other operations cannot access or see the data in an intermediate state during a transaction
DURABILITY --Durability refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone.

> How to find out the database name(schema name) and tables from SQL*PLUS command prompt?
  select * from information_schema.tables
 
> What is output of following query? "Select 2 from employee";
   It depends upon number of rows in table. This query will print 2 as many times as rows in table.
 
> What is the use of CASCADE CONSTRAINTS?
1)-Cascade constraint is used with drop column clause.
2)-Cascade constraint drops all referential integrity constraint primary key and unique key from a multi column table.
3)-Cascade constraint also drop multi column constraint.

    Alter table Emp Drop (PK) cascade constraint;

> What is a default TCP/IP socket assigned for SQL Server?
   1433 is default tcp/ip socket sql server.
   5432 in case of postgresql.
   3306 in case of mysql

> How can i hide a particular table name of our schema.
    We can create in two ways:
    1) using synonym
    2) by using views.

synonym : an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.

> What are two methods of retrieving SQL?
   1-select
   2-using cursor
   stored procedures
Related Posts Plugin for WordPress, Blogger...