Tuesday, 31 July 2012

Object-Oriented CSS,Sprites

Audio Blog:
 http://yourlisten.com/channel/content/16906279/css2

   Hope you would have read my previous post.This is a continuation of CSS there.The concept of OOPS when applied to CSS results it is object oriented CSS.We shouldn't put every attribute concerning a particular object in a single definition.For instance you can seperate the structure from the design.For instance consider a button.Its css file will be given as,

.buttondim{
width:
height:
}
.buttonstyle{
background-color:
font:
text-shadow:
}

Now if you want to use the same sized button anywhere else in the page,you can still use one from the above rather than repeating it.

CSS SPRITES:
    Sprite is an image which is a combination of many other images.It is a single image.The time taken to transmit a big 15k image is less than transmitting three 5k images.
-->Sprites enable us to increase the page efficiency.

Media Query:
  All must be aware of the meta tag in the head.In this tag in the viewport you can mention the media screen .It is used to automatically call different CSS files for different sized screens.The devices need not specify to fetch the different CSS.

Give it as,
@media all and (min-width:500px and max-width:1024)
{
.class1
{
}
.class2
{
}

The "all" in the above sentence specifies all devices.You can specify it as either "monitor" or "print" .
This can also be sometimes implemented when you have many images to be diaplayed in a single frame.The no of images per row is automatically adjusted based on the device size.



- Sourcebits University
Cloud Computing
www.sourcebits.com

Monday, 30 July 2012

CSS Layouts!!

Audio blog:
http://yourlisten.com/channel/content/16906278/css1

BOX model:


The BOX model is used to style elements to specific positions in the screen while using CSS.The above diagram describes about how the page is divided into.The respective wisths are given for each section.Padding is the distance between the border of the element and the content in the element.If the padding border is 0,it is the same as the content border.How we set the widths of these determine the layout of the page perfectly.
-->The margin is the distance outside the given element on all the sides.It is transparent.
-->The border is the border of the element .It has attributes like style,width,color etc..
-->The padding is the distance inside the element to its content on all four sides.
All the sections in the diagram above can set the top,right ,bottom or left widths.They can be either set to fixed widths or in % s.
Positioning of Each an every element you keep in the screen will be placed in this box .The positioning can be either relative ,absolute or fixed.

Fixed positioning:
  You would have seen certain web pages where even when you scroll certain elements will stay in the same place irrespective of scrolling.This is achieved by fixed positioning.
Absolute positioning:In this the position is selected with respect to its parent element.If it is the most outermost element then the measurement will be taken with respect to the total screen width.
eg)
#sec1.sec2{
position:absolute;
top:100px
left:80px
}
In this the elements within sec2 class which is in sec1 id will be at a distance of 100px from top and 80px from left wrt the top and left of the 'sec1' id.
Relative positioning:
Initially these elements are laid out in a static way.Now if you want to move it wrt to its original position use the "relative".This is generally used when you want to move it to certain small measurements from its initial positions.

Suiting all devices:
While designing a page it should be designed to suit devices of all screen size.
Fixed design:
-->Used when all elements must be fixed in locations of the screen.
Fluid Design:
-->While specifying widths it is good to give it in %'s ,so that it will take a percentage of what is totally available.
Elastic Design:
-->Combination of both.Specified in em(square of font size).Page changes as the font size increases.User friendly.Elements which should catch user attention is highlighted.
CSS HACKS:
  I have specified examples of this in the browser specific tags.It is exploiting the weakness or the bugs of a browser.It is actually not good to use ,because in forthcoming versions the bug will be removed and the layout will be out of place.


- Sourcebits University
Cloud Computing
www.sourcebits.com

Friday, 27 July 2012

Browser Specific Elements,Positioning and Dom!

Audio:
http://yourlisten.com/channel/content/16904980/HTML
http://yourlisten.com/channel/content/16904982/html

The problem with Css is that some browsers will interpret the tags and measurements in a different way.The way it interprets varies from browser to browser.And so to write a perfect CSS code,means it should work well with all browsers.
Suppose consider the styling element

#section
{
border-shadow:2px
}
For this to work well in mozilla give it as  -moz-border-shadow
For this to work well in opera give it as  -o-border-shadow
For this to work well in other webkit browsers like chrome and safari give it as  -webkit-border-shadow.

If you have two CSS definitions for the same id then the one it is supposed to take is mostly the last one  .In case you want certain tricks to cheat a specific browser you have a set of tricks,especially for the IE5.An eg is,
suppose you want to give a margin of 25px for internet explorer which is very fine,but this may be sometimes very high for other browsers.Suppose it must work fine for both browsers,use the child selector command.Foe rg

#header{margin-bottom:3em}
html>body #header {margin-bottom :1em}

Now internet explorer will not understand the second line it will only take the first one,while other browsers understand the second one and renders accordingly.


Blink tag:This tag is used to blink a text.But this doesn't work on webkit browsers(chrome+safari).

What is the reason behind browser specific elements??
     This war between the browsers evolved as a result of what is called DOM.It is document object model.The objects which are not listed in the DOM of a specific browser will not work for that browser.The DOM that internet explorer uses will not be understood by the other browsers.



 DOM-Document Object Model:
This is an API which is used to define the logical structure of a document ,the way the elements are accessed and manipulated.
The root element of a document to be accessed is "document".You have different methods to access the elements.
It is an object model that specifies interfaces and not data structure.The relationships that are shown are only logical.
For example you have a "sec1"div and inside that div you have a "sec2" div then you can access the first form in sec2 thats named "f1" by.
document.getElementByID(sec1).getElementBy(sec2).getElementById(f1).

If the DOM retrievals sometime returns an array,it can be accessed with their indexes.

To get the number of anchors in a document give:
document.anchors.length();
To get the number of input elements give,
var x=document.getElementsByTagName("input");

-->The Dom is represented LOGICALLY as a parent child relationship.
-->Starting from the "document" you can access any element in the document and you can retrieve or set their values.
-->The famous ajax technology which is used to retrieve data from the database without reloading,used DOM.The Dom is accessed with the javascript and used for retrieval and manipulation of data.


- Sourcebits University
Cloud Computing
www.sourcebits.com

Thursday, 26 July 2012

Web Front End!!

When you browse through the web site where does those pages come from and how come they are designed??
Obviously they are not stored in the database in the format you see in the front end.When you request a web page from a server it is the combined processing of the


-->Html files
-->Css files
-->Script files that make the front end layout and together with the data retrieved using the database and the framework ,you get what you see on the screen.


HTML is hypertext markup language.Markup language is a language that is used for annotating a document such that it is syntactically distinguishable.This describes the web page as a whole between the <html > and the </html> tage.
It is a good practice to include the end tag for each tag.



HTML:
This has the head section which consists of the subtags
<title>-To display the title
<meta>-To describe the web page and the key words
<base>-default address for all url in the wenpage
<link>-Link to an external file
<script>-LInk to an external script file
<style>-To link to a css file.

Text is given between the <body> and the </body> tags.
The HTML elements are of 2 types,BLOCK elements and the INLINE elements.

Block elements always create a new object in a new line.eg are <p>,<br>,<div> etc
Inline elements are created without a line break in the same line.eg are span,a, etc

<p> creates a new paragraph
<a href="google.com>link</a>-->Used to create a hyperlink
To insert image give

<html>
<body>
<img src="sam.jpg width=90% height=90%/>
</body>
</html>


href ,height and width are  the attributes.There can be many attributes to an element.

Formatting Text:
<b> to make the text bold ,<i> to render it to italics,<em> to emphasize are some of the formatting options.
You can link a given html file to many css files or to many script files.
Css files are used to style the given html file ,to set the layout,background colors and stuff.

<h2 style="background-color:red;">This is a heading</h2>
This is an example of embedding style into a html file between the tags.

Styles and scripts can be added in 3 ways
-->In the html body anywhere
-->Within the script or the style tag.
-->Or in an external file.

The third option is the best option to be followed.
If its an external stylesheet the code should be given in the html is


<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

Setting the layout of the page:
-->In ancient times tables where used to do this work.But it is not a proper option and it is sometimes messy for certain layouts.
--><div> is used instead of that..

What is <div>??
<div> is nothing but a container of type "block " element.
How does it differ from span??
Span is generally used for text.And moreover span is an INLINE element.

You can specify the size and properties of a div element with a unique id ,and many such div elementss combined is taken as a web page.
Each div can be uniquely identified by either "id" or "class" attribute."id" is used whenever there is only 1 of its kind in the page,else "class" is used.

A sample of the web page code i worked with along with its styled output...


AUDIO BLOG:
http://yourlisten.com/channel/content/16904979/HTML_BASIC



- Sourcebits University
Cloud Computing
www.sourcebits.com

Wednesday, 25 July 2012

Document Based Databases!

Audio blog:
http://yourlisten.com/channel/content/16904983/dbd

Document based Databases are one of the important types of Anti-Rdbms.
Reasons why you may look for DBD

They are not relational and are stored in a document as key value pairs.
Document Based Databases do not have a specific schema and so each row has a different structure.
Memory is saved because unnecessary fields are not saved with a NULL value.Saving a NULL value for a field is not the same as having no field.
Examples are MongoDB,CouchDb.
MongoDb is written in c++ and queries are in javascript.
Each tuple in rdbms is analogous to one object in DBD.Several such Json objects are put together to form a document.And so a document is analogous to a table in a DBD.


Insertion and retrievals:
What takes more time for Insertions and retrievals.Let us compare it analogous to both RDBMS and DBD.
In Rdbms each time it does an insertion it has to see for the primary and the foreign key constraints,and map the data entered to the respective fields.All this is taken care of by the ORM.
In DBD that problem doesn't exist because it is just entered as a key value pair,Insertion is made easy.
And when you see with respect to reading or retrieving a file,both takes approximately the same time but in DBD it is only parsing a simple text file.Parsing a text file takes very very less time compared to all other operations in rdbms.

When is DBD useful??
-->It is very useful in high processing computation involves joining of 4-5 tables.
-->Joins can be avoided in DBD compared to RDBMS.
-->Memory is very less,and it is flexible like a class with its own attributes that can be removed or added whenever required.
-->There is no need for normalization.

Disadvantages??
-->Transactions cannot be performed in DBD.Rollback to a certain point and committing it is not possible.So it is better not to perform any secure payment operations using DBD.Setting up of locks is not possible easily though specific DBD's have their own complex mechanisms.
-->When a single object has so many records within it then a single object goes too long and as a result the document will become too large to manage.

Everything that is possible in RDBMS is still possible with the help of DBD.You can still put the different objects in different documents and relate it with something similar to foreign keys but it's again complicating DBD making it to work like RDBMS.When to use what??
Again i think the answer to this depends on the application you use it and the fields that you want to retrieve.

MongoDb:
This has databases,collections,mixtures just like the RDBMS.
Collections contain BSON documents.
It also has no schema and so any new attribute with any new type can be added.
This also facilitates iterative software development which improves flexibilty considerably.

Inserting Data In to the Database:
var t={id:444,name:'rona'};
var h={color:'red',degree:'danger'};

db.cname.save(t);
db.cname.save(h);

To view the documents in a collection we give
db.cname.find();
To retrieve documents having id=444 give
db.cname.find(id:444);
To retrieve the documents with id >7 give,
db.cname.find(id:{'$gt':7});

To update the name to "dd" instead of rona for id=444
db.name.update({id:444}{id:444,name:'dd'});

If you want to set only the name without affecting id use "set" command.
db.name.update({id=444},{'$set':{name:'dd'}});

-->Mongo uses a complete javascript shell and so in the shell and so all you type in javascript can be done in here.
-->printjson()   is an inbuilt function in mongodb.If you want to know what it exactly does all you have to do is "printjson " without "()s" in the shell and you can see the defined function..

>printjson
>function(x)
  print(tojson(x));

To print upto 3 files give
>db.things.find().limit(3);


- Sourcebits University
Cloud Computing
www.sourcebits.com

Tuesday, 24 July 2012

Unix Commands!!

Audio:
http://yourlisten.com/channel/content/16904988/unix
Yes we are talking about the open source operating system Unix.Where you can access almost everything very easily using the terminal.Some of the familiar commands are
ls-To list all the files.
cp source destination-To copy the files from one to another.
mv-To move the file from source to destination.
pwd-Present Working Directory.
mkdir dirname-To make a new directory.
cat fname-To display the contents of the file.
This list keeps going on and on.

You can put all the shell commands together to a sh file and execute it also.To create a file there are 2 methods..
-->Touch filename
-->vi filename

The second option also opens the file and you can switch between 2 modes in that.

Giving Privileges:
The admin of the system can create other users in the system.The right to the users for the various operations and for the access is given by the administrator.This can be achieved by using the 'chmod'.You give it as

+ is used to give access
- is used to remove access
= is used to give exactly the same access..
syntax
chmod ww+qq fname;

where 'ww' can be 'u' or 'a' or 'go'
'u' stands for user
'a' stands for all
'go' stands for group.

'qq' stands for 'r','w',or 'x'
r for read
w for write and x for execute.

Creating users:
sudo adduser uname;
It will ask for a password,give it and create.

To switch between users give
su username

Creating groups:
sudo addgroup gname;
To add user to a group:
sudo adduser uname gname;

Commands for Interconnecting:
ipconfig or ifconfig or ip -a gives the details regarding the network cnnections.You can get information about the ip address here.
ssh-is used to connect between one system to another system..
Syntax:
ssh username@ipaddress
Then give enter give all passwords they prompt and hurrayy you have accessed some other persons terminal.Now incase you want to create a small chat with the person who has logged in to the same address.
Give
write username@ipaddress 'tty'
The tty represents the terminal that is open in the other system.

After typing the above command type in the text and if the other user is logged in the same terminal you can exchange messages..

Transferring Data:
'scp' command is used for transferring data between servers.
You can either copy from one your terminal to a remote server or the other way round.


To check the various connections in your system:

$ netstat -tulnp ;

Copy the file "foobar.txt" from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Grep keyword:
This is used to search for  searching a keyword in a file..
syntax:
grep filename pattern.


The various directories /sbin,/root,/var,/opt etc have specific files related to that.


- Sourcebits University
Cloud Computing
www.sourcebits.com


Monday, 23 July 2012

Advanced concepts in DBMS!

Joins:
What are Joins??Joins are used to combine data and retrieve the data we want from different tables.
Syntax:
EXPLICIT JOIN NOTATIONS:
Select a1,a2,a3 from t1,t2 where c1=c2;
IMPLICIT JOIN NOTATIONS:
select a1,a2 from t1 join t2 on c1=c2;

The simplest kind is the Cross join where The cross join result in cartesian product of all the records from two tables.
Inner Join
if student has rno and rname attributes and
marks has rno and marks attributes then to join them with inner join give it as,

select student.rno,rname,marks from student join marks on marks.rno=student.rno;

You can also use the "using" clause in the above query if the common attributes in both tables have the same name.In our eg "rno" is common ,so u can give it as,

select student.rno,rname,marks from student join marks using(rno);

Equi Join:
If the query performing the join  is based on the equality symbol it is called as equi join.

Left Join:This displays all the records in the table specified in the left even if it doesnt have corresponding matching attributes in the right table.

in the above eg if u want all the roll nos in the db even if their marks are nt entered use this kind of joins.Keyword is "left join".

select student.rno,rname,marks from student left join marks on marks.rno=student.rno;

Right Join:In this case all the records in the marks table will be displayed irrespective of the matching records in the left table ie the student.

select student.rno,rname,marks from student left join marks on marks.rno=student.rno;

Natural Join:
natural join is a type of equi-join where the join predicate arises implicitly by comparing all columns in both tables that have the same column-names in the joined tables. The resulting joined table contains only one column for each pair of equally named columns.

Self Join:
This is used to combine a table to itself.
When you have to find a pairing of all the employess from same country ,u can use this.Remember u have only 1 employee table..

SELECT F.EID, F.Lne, S.ID, S.Lne, F.Country
FROM Employee F
INNER JOIN Employee S ON F.Country = S.Country
WHERE F.EID < S.EID
ORDER BY F.ID, S.ID;

The fourth line is used to reduce the no of comparisons and to find distinct values.





Union:
Unions are used to combine the contents of 2 tables.The number of attributes that you combine should be the same and the type also should be the same.It is used to combine the records,ie the results of 2 queries.



To list all the teachers and the students along with their ID
select tname,tid from teachers union select sname,sid from students;


SUBQUERIES:
  This is when you use the select within another query.This can be used along with select,delete or other insert statements.

To find the country with max population we give..

select country,pop 
from coun
where pop=(select(max(pop) from coun);

Transactions:
To commit a database :
commits the current transaction, making its changes permanent

commit db_name;

 Rollback :

Rolls back to an earlier point undoing the transactions to the last commit operation.

Import Export Database Tables:
I already spoke of creating a dump and storing it in a file in my prev post.To again import the file into the server give
/usr/local/mysql/bin/mysqldump -u uname -p db_name < dumpfile.sql;

Concept of Views Triggers and Procedures:
Create a view:
It is like a dynamic table,made from data extracted from the other tables.
It may be a subset of the other tables.
It occupies only a very little space because only the definition of the view is saved and not the entire data satifying the query.

syntax:



Create view v_name as (select a,b from ttable where c1=c2);
There are also only readable and updatable queries.If it is only readable then update,insert and delete operations in the table will not be effectively reflected in the view.



Procedures:
This is a piece of code that is written and saved in database server.
This is invoked by another program or a trigger or even by another procedure.
Procedures can be recursive.
Advantages and Disadvantages:
Advantages can be reuse,reducing traffic,quick execution etc..
Disadvantages are high load on the database and stuff..So based on the application must decide the use of procedures wisely.

create procedure proc1(Out n1)
begin
  select count(*) into n1 from tab1;
end

Triggers:
  This is the procedural code automatically executed when a db event or change occurs in a table.
This can be used in a case where inserting a new record in 1 table 'marks' must also update another table 'toppers' based on the marks.
That is the insertion in marks should trigger a check on them to insert into 'toppers'.

Syntax:
    CREATE [OR REPLACE] TRIGGER <trigger_name>

    {BEFORE|AFTER} {INSERT|DELETE|UPDATE} ON <table_name>

    [REFERENCING [NEW AS <new_row_name>] [OLD AS <old_row_name>]]

    [FOR EACH ROW [WHEN (<trigger_condition>)]]

    <trigger_body>


eg)

CREATE TABLE T4 (a INTEGER, b CHAR(10));

CREATE TABLE T5 (c CHAR(10), d INTEGER);

CREATE TRIGGER trig1
    AFTER INSERT ON T4
    REFERENCING NEW AS newRow
    FOR EACH ROW
    WHEN (newRow.a <= 10)
    BEGIN
        INSERT INTO T5 VALUES(:newRow.b, :newRow.a);
    END trig1;



When val of a in insertion for t4 is less than 10 then do an insert into t5.

NORMALISATIONS:
This is used to improve the efficiency in the way you manage DBMS.You can easily put all the attributes in a single table and access that from that single table.This single table will now be acting as a GOD  table with all the attributes.But  by doin this there will be so much of redundant data in the database.There will be many copies of the same data in the db and when you make a change in one of the table it may not be reflected in another table having the same attribute.This affects the integrity of the database.
To avoid this you split the data you have to multiple tables and relate the various tables with foriegn keys.
There are many stages in which you avoid the complete redundancy of the data,which is attained with many stages of normalisations.


1)First Normal Form
-->No duplicacy of data
-->No multivalued attributes.
2)Second Normal Form
-->Each tuple must be uniquely identified with the complete set of primary keys,else if individual key is used to identify a tuple,break it into 2 tables;
-->must follow the first normal form.
3)Third Normal Form
-->This removes transitivity.If 'a' depends on 'b' and if 'b' depends on 'c'  where 'a','b','c' are attributes you have to split the tables to 2 different tables.
In addition the 2NF should be followed.
4)Fourth Normal Form:
 -->Must follow all other normal forms + it should avoid all multivalued dependencies.
5)Boyce Code Normal Form:
-->Must follow all the 3 NF .
-->if a,b,c,d are attributes of a table and a,b together form the primary key ,then there can be a condition where a,d-->b,c but not
a,d-->b..If such a case exists it violates BCNF form.


When all the above are attained to a database system then it is highly atomic,and has high integrity and absence of redundancy.Insert,Update and Delete anomolies are also removed.



- Sourcebits University
Cloud Computing
www.sourcebits.com

Sunday, 22 July 2012

Relationship between oops,Data structures,and design patterns!

Now that we have seen what object oriented programming is,how they are created and similarly the data structures now let me try to interconnect them for you.The three topics we speak about here are all what constitute a perfect programming language.I still cant call it perfect,cos there will still be some other defintion for its improvement.
                     Initially the computer age started with abacus and other small computing machines which made work easier.Then it moved on through many stages and reached the era where we could type in and store a series of instructions and then execute it.This is what is followed in procedural languages.But incase of reuse of the instructions or code again and again ,this Procedural languages werent too easy.It created so many copies of the same code at times.To avoid this they moved onto functional and then object oriented languages. In oops you try to model all the entities into a real world model,its how you imagine and set up the attributes,the state and behaviour of the class.This enabled higher degree of modularity and anyone could easily understand the code.And now how is this related to the data structures.When a code is executed where is the compiled code,variables and data stored,all this is decided by the efficient selection of data structures.Each data structure is efficient in its own special way,some in retrieval,in storage and it mainly depends on the application you deal with and the function you want to perform.The right way the objects should be stored and accessed is done right by selecting the best data structure and implementing it the effective way.The combination of modularized code in oops and the efficient implementation and storage in data structure increased overall efficiency effectively.But still there were loop holes in oops,in the way the design was made and the small errors in the mapping to the real world concepts contributed to the imperfection.So the design patterns were introduces which specified more clearly the do'es and do nots of the object oriented structure.Thus one thing evolved to the other and this journey to the perfection will go on for ever and there is no PERFECT code in any progmming language.



- Sourcebits University
Cloud Computing
www.sourcebits.com

Friday, 20 July 2012

Working on retrieval Queries!


Audio
http://yourlisten.com/channel/content/16904992/db2
Video of the screen demo is in this link
http://youtu.be/ckwUl3i3EVI


 In the last post i was discussing a scenario about viewing your own url feeds and the public feed by others.To know the schema of the module please refer to the previous post.
Now let us deal with some of the queries which i worked on today for retrieving from the table.
The tables that i already have are feed,tag,category,feed_tag..
U have to also include a users table which has id has one of the attribute.

Now the u_id in the feeds is related to the id in user.So set the foreign key as
 alter table feed add constraint foreign key(u_id) references users(id);
The cat_id in feed is related to cat_id in category.

alter table feed add constraint foreign key(cat_id) references category(cat_id);


The tag_id in tag is referenced in tag_id of tag_feed table.
alter table tag_feed add constraint foreign key(tag_id)references tag(tag_id);

The f_id in feed is related to the feed_id in tag_feed.
alter table tag_feed add constraint foreign key(feed_id)references feed(f_id);

Now that we have set the foreign key constraints between the tables we will work on the queries.


1)To get the number of feeds for a given category.
query:
    select cat_name,count(*) from category,feed where feed.cat_id=category.cat_id group by cat_name;

2)Display the no of tags for a given feed.

 select feed_url,count(*)as num_of_tags from tag_feed,feed where feed.f_id=tag_feed.feed_id group by feed_url;

3)To display all the public feeds along with the category.
select cat_name,feed_url from category,feed where category.cat_id=feed.cat_id and feed.access="public";

4)To display all the private feeds along with the category.
select cat_name,feed_url from category,feed where category.cat_id=feed.cat_id and feed.access="private";

5)To specify the various user's public feeds along with the category.
select users.user_name,cat_name,feed_url from category,feed,users where users.id=feed.u_id and category.cat_id=feed.cat_id and feed.access="public";

6)To specify the various users private feeds along with the category.

select users.user_name,cat_name,feed_url from category,feed,users where users.id=feed.u_id and category.cat_id=feed.cat_id and feed.access="private";


7)To display the category names along with the count of the tags of the associated feeds.

select DISTINCT cat_name,tag.tag_name from category,feed,tag_feed,tag where category.cat_id=feed.cat_id and feed.f_id=tag_feed.feed_id and tag.tag_id=tag_feed.tag_id;

8)To display the category names along with the count of the tags of the associated feeds.

select cat_name,count(*) from category,tag where (cat_name,tag_name) IN (select DISTINCT cat_name,tag.tag_name from category,feed,tag_feed,tag where category.cat_id=feed.cat_id and feed.f_id=tag_feed.feed_id and tag.tag_id=tag_feed.tag_id)group by cat_name;




How do i link the various modules which the users work on different servers??
I have always wondered and found an answer today.It is using the database dump file.You give the command,

mysqldump db_name -u user_name -p password.
Hurray and the dump file is created.

Now you can put it in a text file using the command
mysqldump db_name -u user_name -p password >> filedump.txt;
And this file can be used by others to create their schema :)

1)Queries using max:

Used to group with the maximum in each.
select type,max(val) from tab1 group by(type);

2)Queries using min:

Used to group with the minimum in each.
select type,min(val) from tab1 group by(type);

Used to group with the avg in each.
select type,avg(val) from tab1 group by(type);

WHERE CLAUSES
1)AND..You can give multiple conditions in where clauses where both are to be true.
2)Or..You can use it to combine multiple clauses where any of them can be true.
3)Not..Used to specify the negation of the where clause..
4)Like..Used to identify the patterns in the column,
WHERE column_name LIKE pattern
5)Not LIKE..Used to identify those columns which doesnt match a pattern.
6)NULL..
NULL values represent missing unknown data. By default, a table column can holdNULL values.
7)NOT NULL..
The NOT NULL constraint enforces a column to NOT accept NULL values. 
OTHER CLAUSES
ORDER by:
This is used to sort in the ascending or the descending order of a particular column.
Offset:This is from where the retrieval should start..
Limit:This is used to limit the number of records to be retreived.
syntax: sql statement LIMIT [N]


limit and offset can be combined by using comma in limit clause.






Hope it helped.



- Sourcebits University
Cloud Computing
www.sourcebits.com

Thursday, 19 July 2012

Understanding with a Scenario!

Now today il try explaining you the various terms with a help of a mini scenario the various terms in DB.
Consider a case where users can login to a system with a unique username and password.Once they login they can add a url feed in to their account.This feeD can be either categorized as public or private.If it is a private fiels only you can access it,or view it.All other people will never know that you ever included that news feed.If it is public all can view.
   In a user's home page we will have both the private and the public option.In the public option you can view the feed urls that all the other users have included and have put it in the public access mode.
  A feed can belong to one category and has multiple posts.

We will create the design to implement the above functionality.
1)Consider what has to be created as the Master Table.A master table is the table which is important in performing the functionality.In our case  USER is a table with various attributes..

CREATE TABLE USER(
u_id int,
u_name varchar(20),
u_pwd varchar(20),
primary key(u_id)
);

Here u_id is unique in the table,no 2 users can have d same u_id,so it is given under the primary key constraint.
Next master table is FEED.

CREATE TABLE FEED(
f_id int(20),
f_url varchar(20),
cat_id int(4),
access varchar(20),
u_id int(4)
primary key(f_id)
NOT NULL(f_url)
);


NOT NULL(f_url) specifies that f_url should never be left null,must always contain a value.

Now u_id from USER table is the foreign key set it as


ALTER TABLE FEED
ADD FOREIGN KEY (U_Id)
REFERENCES USER(U_Id)



In each stage the datatype is to be correctly chosen ,based on the usage.
One FEED will have multiple tags,so it is a MANY-MANY relation .So introduce a intermediate table called TAG_FEED..


CREATE TABLE TAG_FEED
(t_id int(4),
f_id int(4),
);


If you put t_id in the FEED table it will lead to redundancy as the feed name and everything will be repeated.So this is done.Now create a TAG table.

CREATE  TABLE TAG
(
t_id int(4),
t_name varchar(20)
primary key(t_id)
);



CREATE  TABLE CATEGORY
(
c_id int(4),
c_name varchar(20)
primary key(c_id)
);


Now you may ask,why can't you create a relationship table for category and feed.
Answer is we do it only when many-many relationship exists ,else it is not required.There is only 1 category for a feed,so you don't include a relationship table.


Once you create the schematic structure you have to populate the tables and use the queries to efficiently retrieve them.


Naming convention for Columns:
There are different standards for naming the column names.
I will discuss with you the oracle standard here.


Column names should be spelled out whenever possible.
If a column name should exceed 30 characters, reduce the size of the column name in this order:

  • From the left of the column name, remove vowels from each word in the table name except for the first vowel of each word.
  •  If the column name is still greater than 30 characters, use standardized shorthand indicators. Record this standard for consistent use.

Creating Default values for fields:
While creating a table if you want to set a default value for your table ypu can do it as 
Create table tab1
(
id int(3)
value int(4),
number int(2) DEFAULT 4
);

Now 4 is the default value for number.


MODIFY TABLE and MODIFY EXISTING COLUMN::
ALTER TABLE table_name MODIFY column_name datatype;


ADD NEW COLUMN:

ALTER TABLE table_name
ADD column_name datatype

Delete 
ALTER TABLE table_name 
DROP COLUMN column_name


RENAME COLUMN NAME OR CHANGE COLUMN TYPE:
ALTER TABLE tab_name
 change old_col new_col 
data_type


UPDATE/DELETE/TRUNCATE TABLE:
Deleting a table:
drop table tab_name;
eg) drop table emp;

Update a table:
   update table_name set field1=value1,field2=value2 where condition;

e.g.)update employee set e_name ='ttt' where e_no=6;

INSERT DATA INTO TABLE:
insert into tab_name values(val1,val2,val3);


eg)insert into emp values(1,'ron','cm');


BULK INSERT



insert into your_table (field1, field2, field3)
values 
  (value1_1, value1_2, value1_3), 
  (value2_1, value2_2, value2_3), 
  (value3_1, value3_2, value3_3)
insert into table1 (no, name, desg)
values 
  (1, 'qqq', 'cm'), 
  (2, 'www', 'acm'), 
  (3, 'ttt', 'dce');

- Sourcebits University
Cloud Computing