To rename the table name the syntax is as follows:
Syntax:
rename current_table_name to new_table_name;
Example:
rename students to student;
Monday, January 24, 2011
Monday, January 3, 2011
SQL SERVER – Definition, Comparison and Difference between HAVING and WHERE Clause
In recent interview sessions in hiring process I asked this question to every prospect who said they know basic SQL. Surprisingly, none answered me correct. They knew lots of things in details but not this simple one. One prospect said he does not know cause it is not on this Blog. Well, here we are with same topic online.
Answer in one line is : HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.
HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
A HAVING clause is like a WHERE clause, but applies only to groups as a whole, whereas the WHERE clause applies to individual rows. A query can contain both a WHERE clause and a HAVING clause. The WHERE clause is applied first to the individual rows in the tables . Only the rows that meet the conditions in the WHERE clause are grouped. The HAVING clause is then applied to the rows in the result set. Only the groups that meet the HAVING conditions appear in the query output. You can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function. (Reference :BOL)
Example of HAVING and WHERE in one query:
SELECT titles.pub_id, AVG(titles.price)
FROM titles INNER JOIN publishers
ON titles.pub_id = publishers.pub_id
WHERE publishers.state = 'CA'
GROUP BY titles.pub_id
HAVING AVG(titles.price) > 10
Sometimes you can specify the same set of rows using either a WHERE clause or a HAVING clause. In such cases, one method is not more or less efficient than the other. The optimizer always automatically analyzes each statement you enter and selects an efficient means of executing it. It is best to use the syntax that most clearly describes the desired result. In general, that means eliminating undesired rows in earlier clauses.
Answer in one line is : HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.
HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
A HAVING clause is like a WHERE clause, but applies only to groups as a whole, whereas the WHERE clause applies to individual rows. A query can contain both a WHERE clause and a HAVING clause. The WHERE clause is applied first to the individual rows in the tables . Only the rows that meet the conditions in the WHERE clause are grouped. The HAVING clause is then applied to the rows in the result set. Only the groups that meet the HAVING conditions appear in the query output. You can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function. (Reference :BOL)
Example of HAVING and WHERE in one query:
SELECT titles.pub_id, AVG(titles.price)
FROM titles INNER JOIN publishers
ON titles.pub_id = publishers.pub_id
WHERE publishers.state = 'CA'
GROUP BY titles.pub_id
HAVING AVG(titles.price) > 10
Sometimes you can specify the same set of rows using either a WHERE clause or a HAVING clause. In such cases, one method is not more or less efficient than the other. The optimizer always automatically analyzes each statement you enter and selects an efficient means of executing it. It is best to use the syntax that most clearly describes the desired result. In general, that means eliminating undesired rows in earlier clauses.
Sunday, January 2, 2011
HTML Tags.
The following are tags using in HTML 5.
<!-->
<!DOCTYPE>
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdo>
<big>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<datalist>
<dd>
<del>
<details>
<dfn>
<dir>
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1> - <h6>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<keygen>
<kbd>
<label>
<legend>
<li>
<link>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
<!-->
<!DOCTYPE>
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdo>
<big>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<datalist>
<dd>
<del>
<details>
<dfn>
<dir>
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1> - <h6>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<keygen>
<kbd>
<label>
<legend>
<li>
<link>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
Saturday, January 1, 2011
Shell Environment.
To find all available shells in our system type following command.
syntax:
cat /etc/shells
To find our current shell type following command.
syntax:
echo $SHELL
Sunday, December 26, 2010
Compiling C Program Under Unix
To compile the C program under Unix environment. We need C Compiler to compile C program. Some C compilers are cc, gcc and etc., In this cc compiler is available under any environment. To compile:
cc file_name.c
this will compile C program. To run,
./a.out
Example:
cc sample.c
To run this,
./a.out
Another way,
cc -o output_file file_name.c
To run this,
./output_file
Example:
cc -o sampleout sample.c
To run,
./sampleout
Linux Filesystem
As a Linux system boots, the filesystem that becomes available is the top level, or rot filesystem, denoted with a single forward slash(/). The root filesystem /, also known as root directory, shouldn't be confused with the root superuser account or the superuser's home directory, / root. In a installation, the root filesystem could contain nearly everything on the system. As the Linux kernel boots, the partitions are mounted to the root filesystem, and together create a single unified filesystem. Everything on the system that is not stored in a mounted partition is stored locally in the / partition. The mounted filesystem are placed on separate partitions and possibly multiple disk drives. Here is the list of directories the root filesystem contains:
/ (the root directory): Since the only filesystem mounted at the start of the boot process is /, certain directories must be part of it to be available for the boot process. These include:
/bin and /sbin: Contains required system binary programs.
/dev: Contains device files.
/etc: Contains configuration information used on boot.
/lib: Contains shared libraries. These directories are always part of the single / partition.
/boot: This directories holds static files used by the boot loader, including kernel images. On system where kernel development activity occurs regularly, making /boot a partition eliminates the possibility that / will fill with kernel images and associated files during development.
/home: User files are usually placed in a partition. This is often the largest partition on the system and may be located on a separate physical disk or disk array.
/tmp: This directory is often a separate partition used to prevent temporary file from filling the root filesystem.
/var: Log files are stored here. This is similar to the situation with /tmp, where user files can fill any available space if something goes wrong or if the files are not cleaned periodically.
/usr: This directory hold a hierarchy of directories containing user commands, source code, and documentation. It is often quite large, making it a good candidate for its own partition. Because much of the information stored under /usr is static, some users prefer that it be mounted as read-only, making it impossible to corrupt.
In addition to the preceding six partitions listed, a swap partition is also necessary for a Linux system to enable virtual memory.
Tuesday, December 7, 2010
Access specifier
In Object Oriented Programming there are three types of access specifier is available. They are:
1.private
2.public
3.protected
private:
private members are private to class,which mean it allows the instance member to access within the class, access beyond that class scope makes error.
private data members are accessed through class public member functions.
In C++ private is default to class it means if we didn't specify any specifier its private to that class
public:
public members are public to a program/class, which means its like global variable of a program/class, we can access anywhere in the program/class. In java public is default to class it means if we didn't specify any specifier its public to that program/class.
protected:
protected is same as private, we cant able to access the protected variable beyond a class scope. But, when we inherit the protected members of a class, we can able to access those protected member as private to that derived class.
1.private
2.public
3.protected
syntax:
access_specifer:
member declarations;
private:
private members are private to class,which mean it allows the instance member to access within the class, access beyond that class scope makes error.
private data members are accessed through class public member functions.
In C++ private is default to class it means if we didn't specify any specifier its private to that class
syntax:
private:
member declaration;
Example:
private:
int reg_no;
public:
public members are public to a program/class, which means its like global variable of a program/class, we can access anywhere in the program/class. In java public is default to class it means if we didn't specify any specifier its public to that program/class.
syntax:
public:
member declaration;
Example:
public:
reg_no;
protected:
protected is same as private, we cant able to access the protected variable beyond a class scope. But, when we inherit the protected members of a class, we can able to access those protected member as private to that derived class.
syntax:
protected:
member declartion;
Example:
protected:
char address[40];
Subscribe to:
Posts (Atom)