Friday, January 28, 2011

creating and running a python file

create a python file:

vi file_name.py

the extension of python file is .py
to check python libraries are installed on your system, type python in shell, this will shows the version and options in python.

example:
vi hello.py

the above command will create a python file with file name as hello.

running python scripts:

python file_name.py

the above command will run the python scripts.

example:

>vi hello.py
print("Hello world!")

>python hello.py
output:Hello world!

First hello world program in python

syntax:
print("message")

example:
print("Hello world!!")

Wednesday, January 26, 2011

Solution:changing directory delimits to white space.

while changing directory, cd command delimits to white spaces.

syntax:
cd directory_name

is the syntax for changing directory. cd command workout with directory without whitespace.

example:
cd Documents

this will workout. But if the directory name is 'pdf files' cd command

cd pdf files

will wont work out 'cd: pdf no such file or directory' will be the result if there is no 'pdf' directory this is because cd command takes 'pdf' as a directory, which delimits to white space. The cd command resolved by '\' before whitespace. The above example can resolved as,

cd pdf\ files

suppose the directory contains two whitespace i.e,'pdf  files', the command will be,

cd pdf\ \ files.

if your directory is 'pdf\files', then the command for changing directory is

cd pdf\\files.

Monday, January 24, 2011

Renaming a Column in a table

To rename the columns(attributes)in a table the syntax is as follows:

syntax:

alter table table_name rename column current_column_name to new_column_name;



Example:


alter table student rename column stud_dept to dept_id;

Renaming a Table name

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 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.

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>





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