Friday, June 11, 2010

All about Database Keys


ShareThis

Database Keys

Introduction
For the purposes of clarity we will refer to keys in terms of RDBMS tables but the same definition, principle and naming applies equally to Entity Modelling and Normalisation.
Keys are, as their name suggests, a key part of a relational database and a vital part of the structure of a table. They ensure each record within a table can be uniquely identified by one or a combination of fields within the table. They help enforce integrity and help identify the relationship between tables. There are three main types of keys, candidate keys, primary keys and foreign keys. There is also an alternative key or secondary key that can be used, as the name suggests, as a secondary or alternative key to the primary key
Super Key
A Super key is any combination of fields within a table that uniquely identifies each record within that table.
Candidate Key
A candidate is a subset of a super key. A candidate key is a single field or the least combination of fields that uniquely identifies each record in the table. The least combination of fields distinguishes a candidate key from a super key. Every table must have at least one candidate key.
Candidate Kay
As an example we might have a student_id that uniquely identifies the students in a student table. This would be a candidate key. But in the same table we might have the student’s first name and last name that also, when combined, uniquely identify the student in a student table. These would both be candidate keys.
In order to be eligible for a candidate key it must pass certain criteria.
  • It must contain unique values
  • It must not contain null values
  • It contains the minimum number of fields to ensure uniqueness
  • It must uniquely identify each record in the table
Once your candidate keys have been identified you can now select one to be your primary key
Primary Key
A primary key is a candidate key that is most appropriate to be the main reference key for the table. As its name suggests, it is the primary key of reference for the table and is used throughout the database to help establish relationships with other tables. As with any candidate key the primary key must contain unique values, must never be null and uniquely identify each record in the table.
As an example, a student id might be a primary key in a student table, a department code in a table of all departments in an organisation. This module has the code DH3D 35 that is no doubt used in a database somewhere to identify RDBMS as a unit in a table of modules. In the table below we have selected the candidate key student_id to be our most appropriate primary key
Primary Key
Primary keys are mandatory for every table each record must have a value for its primary key. When choosing a primary key from the pool of candidate keys always choose a single simple key over a composite key.
Foreign Key
A foreign key is generally a primary key from one table that appears as a field in another where the first table has a relationship to the second. In other words, if we had a table A with a primary key X that linked to a table B where X was a field in B, then X would be a foreign key in B.
An example might be a student table that contains the course_id the student is attending. Another table lists the courses on offer with course_id being the primary key. The 2 tables are linked through course_id and as such course_id would be a foreign key in the student table.
Foreign Key
Secondary Key or Alternative Key
A table may have one or more choices for the primary key. Collectively these are known as candidate keys as discuss earlier. One is selected as the primary key. Those not selected are known as secondary keys or alternative keys.
For example in the table showing candidate keys above we identified two candidate keys, studentId and firstName + lastName. The studentId would be the most appropriate for a primary key leaving the other candidate key as secondary or alternative key. It should be noted for the other key to be candidate keys, we are assuming you will never have a person with the same first and last name combination. As this is unlikely we might consider fistName+lastName to be a suspect candidate key as it would be restrictive of the data you might enter. It would seem a shame to not allow John Smith onto a course just because there was already another John Smith.
Simple Key
Any of the keys described before (ie primary, secondary or foreign) may comprise one or more fields, for example if firstName and lastName was our key this would be a key of two fields where as studentId is only one. A simple key consists of a single field to uniquely identify a record. In addition the field in itself cannot be broken down into other fields, for example, studentId, which uniquely identifies a particular student, is a single field and therefore is a simple key. No two students would have the same student number.
Compound Key
A compound key consists of more than one field to uniquely identify a record. A compound key is distinguished from a composite key because each field, which makes up the primary key, is also a simple key in its own right. An example might be a table that represents the modules a student is attending. This table has a studentId and a moduleCode as its primary key. Each of the fields that make up the primary key are simple keys because each represents a unique reference when identifying a student in one instance and a module in the other.
Composite Key
A composite key consists of more than one field to uniquely identify a record. This differs from a compound key in that one or more of the attributes, which make up the key, are not simple keys in their own right. Taking the example from compound key, imagine we identified a student by their firstName + lastName. In our table representing students on modules our primary key would now be firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference to a student, they are not each simple keys, they have to be combined in order to uniquely identify the student. Therefore the key for this table is a composite key.

Extracted From: http://rdbms.opengrass.net/2_Database%20Design/2.1_TermsOfReference/2.1.2_Keys.html

Thursday, June 10, 2010

What is HTML Debugging?


ShareThis

Today, some one asked me “What is HTML debugging?”

So I thought to share the answer to you also..

HTML is a formatting language for displaying text, graphics and multimedia in web pages.

When Client side scripting (script that run within the browser and consumes resources like processor and RAM from the same computer) is included with HTML its Called DHTML.

There are many client side languages like : DHTML Script, Java Script (JS) and Visual  basic (VB Script)

HTML itself can't be debugged. So HTML debugging generally mans to debug HTML with the embedded Java Script or VB script.

Sometimes HTML with the embedded CSS is debugged by a tool called Firebug or similar tools within the browser to find some errors, display problems.. this is also called HTML debugging.

I think this is the answer to your question.
Pls. let me know if any clarification required.

See this article to know more how Firebug is used to debug HTML/ CSS/ JS in Firefox browser.

http://kb.siteground.com/article/How_to_debug_HTMLCSS_issues_using_Firefox.html

This article let you know how to debug HTML in Internet explorer browser using developer tools:

http://msdn.microsoft.com/en-us/library/dd565627(VS.85).aspx

How Search Works


ShareThis
How Search Works

Here is a good video from Google that describes how search works…

Google launches it new web indexing system called Caffeine


ShareThis

Google has launched a new search indexing system that seems more effective and interesting. This indexing suits the needs of dynamic web of the current time.

According to Google:

So why did we build a new search indexing system? Content on the web is blossoming. It's growing not just in size and numbers but with the advent of video, images, news and real-time updates, the average webpage is richer and more complex. In addition, people's expectations for search are higher than they used to be. Searchers want to find the latest relevant content and publishers expect to be found the instant they publish.

To keep up with the evolution of the web and to meet rising user expectations, we've built Caffeine. The image below illustrates how our old indexing system worked compared to Caffeine:

Our old index had several layers, some of which were refreshed at a faster rate than others; the main layer would update every couple of weeks. To refresh a layer of the old index, we would analyze the entire web, which meant there was a significant delay between when we found a page and made it available to you.

With Caffeine, we analyze the web in small portions and update our search index on a continuous basis, globally. As we find new pages, or new information on existing pages, we can add these straight to the index. That means you can find fresher information than ever before — no matter when or where it was published.

Caffeine lets us index web pages on an enormous scale. In fact, every second Caffeine processes hundreds of thousands of pages in parallel. If this were a pile of paper it would grow three miles taller every second. Caffeine takes up nearly 100 million gigabytes of storage in one database and adds new information at a rate of hundreds of thousands of gigabytes per day. You would need 625,000 of the largest iPods to store that much information; if these were stacked end-to-end they would go for more than 40 miles.

We've built Caffeine with the future in mind. Not only is it fresher, it's a robust foundation that makes it possible for us to build an even faster and comprehensive search engine that scales with the growth of information online, and delivers even more relevant search results to you. So stay tuned, and look for more improvements in the months to come.

For complete article  visit this Google Blog Page.

Friday, May 28, 2010

Computer Emergency Response Team of India – A good initiative


ShareThis

Promoted by CERT India and set up in active collaboration with Microsoft India, SecureFirst acts as a neutral body to disseminate information on security for everyone—from home-users to small businesses to the government and corporate sphere.

SecureFirst aims to create awareness among people and to provide exhaustive information on security so that the users are vigilant and ready to combat the online threats and perils.

The Computer Emergency Response Team, India (CERT-In) provides necessary assistance to prevent security breaches. The team also monitors the cyber security scenario in the country.

The endeavour is Supported by NASCOM, CII & Microsoft. This site can be a good resource for Internet users, parents, females and children.
With activities such as Net surfing, online gaming, and chatting becoming more popular, the number of children accessing the Web has increased drastically. Easy accessibility to computers has played a key role in this. However, with such easy access and technology knowledge also comes some responsibility.

There are infinite reasons for being cautious. There is an equally long list of tips and guidelines on maintaining your online privacy and safeguarding your security. The most important of them are mentioned below.

  • Exercise Caution: If a member of a chat room or forum is soliciting your attention or friendship, share it with your parents or elders
  • Be Vigilant: Close any conversation with an online acquaintance the moment you feel uncomfortable; always save the conversation you have with such strangers
  • Be Aware: Do not give out your telephone number or street address, and do not agree to meet any chat friends in person

There are lot of other useful information on the website. A good site for helping on the issues of cyber crime in English, Hindi and Marathi.

The website can be accessed here:

http://www.cert-in.org.in/securepc/

MICROSOFT SECURITY INTELLIGENCE REPORT (SIR)


ShareThis

The Microsoft Security Intelligence Report (SIR) has become established as the most comprehensive and detailed examination of the evolving threat landscape. Microsoft is committed to combating online threats and to educate the industry around today’s evolving threat landscape.

Microsoft has released volume 8 of the Microsoft Security Intelligence Report (www.microsoft.com/sir). This volume of the SIR covers the period from 1st July – 30th December 2009 and builds on telemetry and analysis over the past several years.

Although threats and techniques are becoming more sophisticated worldwide, SIR v8 reinforces that observing security fundamentals, like staying up-to-date on the latest security updates and migrating to newer software, can help IT professionals and home users achieve safer, more trusted Internet experiences. The data shows that malware infection rates on Windows 7 and Windows Vista SP2 are 50 percent less than on its predecessor, Windows XP. Key findings include the following information:

  • Data in SIRv8 shows that techniques used in pursuit of Cybercrime continue to mature, Mirroring Traditional Business Techniques. Cyber criminals are becoming increasingly sophisticated, financially motivated and organized to turn Cybercrime into a business.
  • Security Fundamentals and Technology Innovation Are Raising the Bar on Cybercrime – SIR v8 shows that following security fundamentals and migrating away from older technology can successfully mitigate potential attacks. Using latest versions mean you are less likely to be compromised. Installing security updates is the fundamental Internet security best practice regardless of whether you are using latest versions or old software.
  • We all need to do more to defend against Cybercrime – an industry-wide challenge - Producing software products that continue to contain vulnerabilities that criminals are showing themselves to be increasingly effective at finding and exploiting is a challenge as shown in SIR v8. For instance, a higher proportion of web-based malware exploits succeed against 3rd-party applications rather than the underlying OS or browser, when the OS and browser have been strengthened through security development processes (which I have discussed in the previous issues of Security Focus). Cyber criminals are not going away, but organizations can limit their success by adopting mitigating strategies to protect network, systems and people. No one individual, company, or technology can solve the security and privacy challenges we face online today. Microsoft encourages the global security and privacy communities, individuals and groups of internet users and others throughout the industry to work together through a community-based defense approach to help create a safer, more trusted Internet.
    In India, we have seen
  • that the threat landscape was dominated by malware, which accounted for 77.1 percent of all threats detected on infected computers in 2H09.
  • the most common category in India was Worms, which accounted for 20.6 percent of all infected computers.
  • together, Miscellaneous Trojans and Trojan Downloaders & Droppers made up more than 32 percent of all families detected on infected computers in India in second half of 2009.
  • Four of the eleven most prevalent threats detected in India during second half of 2009 (Win32/Taterf, Win32/Hamweq, Win32/Conficker and Win32/Autorun) spread via mapped drives with weak or missing passwords, removable media (such as USB drives), or a combination of both.
  • Win32/Renos, the second-most prevalent family in India in second half of 2009, was also the second-most prevalent threat detected worldwide. Win32/Renos is a family of trojan downloaders that install rogue security software. (Rogue security software — software that displays false or misleading alerts about infections or vulnerabilities on the victim’s computer and offers to fix the supposed problems for a price — has become one of the most common methods that attackers use to swindle money from victims.)
  • Win32/Taterf ranked first in the world and in India Win32/Taterf ranked third, (Win32/Taterf: A family of worms that spread through mapped drives to steal login and account details for popular online games.)
  • Win32/Ardamax, the fourth-most prevalent family detected in India in second half of 2009, does not appear in the top 25 families detected worldwide. Win32/Ardamax is a key-logger program that can capture user activity and save it to a text or HTML file. Win32/Ardamax can be configured to send these files via e-mail to a predefined address.

Extract from Microsoft Newsletter.

The Complete report can be read here:
http://www.microsoft.com/security/about/sir.aspx

Saturday, May 22, 2010

Full Social Media Integration for Marketing


ShareThis

Tuesday, May 18, 2010

Web 3.0 –The semantic web


ShareThis
Web3.0 The semantic web.The Semantic Web provides a common framework that allows data to be shared and reused across application, enterprise, and community boundaries. It is a collaborative effort led by W3C with participation from a large number of researchers and industrial partners. It is based on the Resource Description Framework (RDF). Wikipedia describes Semantic web as,The Semantic Web is an evolving development of the World Wide Web in which the meaning (semantics) of information on the web is defined, making it possible for machines to process it.According to semanticweb.org,The Semantic Web is the extension of the World Wide Web that enables people to share content beyond the boundaries of applications and websites. It has been described in rather different ways: as a utopic vision, as a web of data, or merely as a natural paradigm shift in our daily use of the Web. Most of all, the Semantic Web has inspired and engaged many people to create innovative semantic technologies and applications. semanticweb.org is the common platform for this community

Semantic web is the future. I assume the coming era will be of semantic web.

I found a really good presentation that well describes web 1.0, web 2.0 and web 3.0 in detail with suitable examples.

It’s a must watch presentation for Web designers, developers, planners, architects and IT businessmen.Presentation by: Hatem Mahmoud.

Semantic Web a simple description:

The semantic web stack described by Wikipedia:

Another good presentation on web evolution from web 0 to web 3.0 by Liam O'Morain
can be found on youtube:

Few places I would suggest to go to for learning more on semantic web :

http://www.w3.org/2001/sw/

http://semanticweb.org/wiki/Main_Page

http://en.wikipedia.org/wiki/Semantic_Web

http://www.w3.org/2001/sw/SW-FAQ

For developers here is :

A Semantic Web Primer for Object-Oriented Software Developers

Web 3.0 –The semantic web


ShareThis
Web3.0 The semantic web.I found a really good presentation that well describes web 1.0, web 2.0 and web 3.0 in detail with suitable examples.

Presentation by: Hatem Mahmoud.

Saturday, May 15, 2010

Understanding Concurrency Control in SQL Server


ShareThis

Understanding Concurrency Control Options

When multiple users need to access the same data simultaneously, or better yet, update it concurrently, SQL Server must somehow control how these reads and writes to the database are carried out. The two basic controlling options are transaction isolation levels and--especially when updating data--locks.

You are probably familiar at least with the concept of both. However, SQL Server is a complex product, and thus both transaction isolation levels and locking have dozens of different options that will affect the way your applications behave when multiple users use the same database objects simultaneously. Depending on the options selected and the order of events occurring (read, then write, or the other way around), different operations are done by the database server.

Concurrency control is usually divided into two broad categories: pessimistic and optimistic concurrency control. Shortly put, pessimistic concurrency assumes that multiple users will try to update the same rows often, and thus locking is used to control the order in which updates succeed and which will have to wait.

On the other hand, optimistic concurrency can be said to assume the opposite: updates to the same database objects (table rows in particular) are few, and thus an error message on the client is enough to handle the situation when a second user tries to update the same object.

Of course, these are only the broad lines. To understand concurrency control and locking in detail, it's best to start with a quick overview of transaction isolation levels in SQL Server 2008.

 

Briefly About Transaction Isolation Levels

SQL Server 2008 (Figure 1) supports five transaction isolation levels, each of which is part of the SQL standard from 1992. The main idea of different isolation levels is to control how other users (technically, other transactions) see modifications (inserts, updates and deletes) from other transactions. In addition, they specify how locks are being held, which in turn affects performance: how many users can read and write the same database objects at the same time.

 

The isolation levels supported by SQL Server 2008 are named READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SNAPSHOT, and SERIALIZABLE. The READ UNCOMMITTED is the least restricted level, and allows reading changes made by other transactions, even if those changes have not yet been committed. The other end of the spectrum is SNAPSHOT, which specifies that a transaction can only read committed data that existed when the transaction started. No chances will be visible during the lifetime of a transaction using the snapshot isolation.

The transaction isolation level can be set using T-SQL statements, but more commonly, it is set using the class libraries used by the application code. For instance when using the ADO.NET SqlConnection class (in the

System.Data.SqlClient

namespace), you can use the

BeginTransaction

method to specify which isolation level you want to use. The

IsolationLevel

enumeration is used to specify the preferred option, and it defaults to

ReadCommitted

. This corresponds to the database engine level

READ COMMITTED

.

Understanding Locking Modes

To gain an understanding of how locking works, you need to be aware of different transaction levels and the different lock modes ("types") supported by SQL Server 2008. The following list shows the most common lock modes, along with their abbreviation in parenthesis:

  • Shared locks (S)
  • Update locks (U)
  • Exclusive locks (X)
  • Intent locks (I)
  • Schema locks (two types, SCH-M and SCH-S)
  • Bulk Update locks (BU)
  • Key-range locks (R)

SQL Server supports many different lock modes and this can be somewhat complex at times. Learning is best to start from exclusive locks, which are the easiest to understand. Shortly put, an exclusive lock (X) is placed on a database object whenever it is updated with an INSERT or UPDATE statement.

At the other end of the spectrum, the shared locks (S) is put to a database object whenever it is being read (using the SELECT statement), depending on the selected transaction isolation mode. Between the shared and exclusive locks, there is the update lock (U), which can be thought of as an in-between mode between shared and exclusive locks. The main purpose of the update lock is to prevent deadlocks where multiple users simultaneously try to update data.

Intent locks are used to indicate that a certain lock will be later placed on a certain database object. Intent locks are used because locks can form hierarchies. Intent locks prevent the potential situation where a newly-acquired lock might invalidate locks on a lower level in the hierarchy.

Finally, schema locks (SCH-M and SCH-S) are used to prevent changes to object structure, bulk update locks (BU) are used when updating or inserting multiple rows using a bulk update, and key-range locks (R) are used to lock ranges of keys in an index. Key-range locks are used with the SERIALIZABLE transaction isolation level to prevent phantom reads, for instance.

In addition to singular locking modes, certain locking modes can be combined with one another. This is especially true with intent locks, which are can be form pairs such as intent shared (IS), intent update (IU), and so forth.

Because maintaining locks can be an expensive operation performance-wise, SQL Server supports a feature called multigranular locking. This means that locks can be placed on different levels, depending on the situation. For instance, a lock can be places on a single table row, a table page (internal storage unit), an entire table, and so on. Sometimes, SQL Server needs to place multiple locks on different levels. These locks then form a locking hierarchy, and intent locks play a role in this, as described above.

Lock Compatibility and Reading Information About Locks

As an application developer or a database administrator, you need to understand how locking works. Part of this understanding is to know how locking compatibility affects your applications. SQL Server calls this technically lock compatibility, but some of it is just common sense: an update cannot be made while another user has already locked the same data exclusively.

Because there are over 20 different locking mode combinations in SQL Server 2008, the SQL Server documentation (Books Online, BOL) contains a complete matrix of all the different locking combinations and their outcome. For instance, will the two types of locks live peacefully together (no locking conflict), or will either an error or delay occur (a conflict)? When using ADO.NET, a statement that causes a lock conflict will usually wait until a timeout occurs, or until the lock is released by another transaction. As locking compatibility has dozens of tiny options, for the purpose of this article, it is enough to understand the main rule: if a database object is already locked by another transaction, a new lock can only be placed on the object if the two lock modes are compatible with one another. Also, almost no other lock type is compatible with the exclusive (X) lock, meaning that if an exclusive lock is already placed on the object, most later lock requests fail.

How SQL Server places locks on object depends on the transaction isolation level currently active. For instance, the default read committed isolation mode does not place shared locks when reading data (think SELECT statements), but if the isolation level is for example repeatable read (a step higher level), then shared locks will be placed on objects that are being read. This is to make sure the identical data can be read again.

All this sounds interesting, but how could you see locking in action yourself? The answer lies in a system view called sys.dm_tran_locks kept by SQL Server. You can query this view, and thus find information about locking in real-time. Although you could use the SQL Server Management Studio to retrieve this information, it's easy to write a .NET application with C# that shows you the results in a nice, easy-to-read grid.

Such an application can be seen in Figure 2. On the left, you can see the application's main form, which contains several buttons to connect and disconnect from the database, start a transaction with the selected transaction isolation level and either commit or roll back the transaction. At the bottom, you can find a button to execute the entered SQL statement (such as SELECT or UPDATE), and finally the button to open the Locks window, shown on the right. From this window, you can see locks acquired by SQL Server. The lock mode abbreviation (such as S or X) is shown in the request_mode column.

 

Figure 2. A simple .NET application can easily retrieve real-time information about locks

The implementation of the application is very straightforward, and uses classes such asSqlConnection, SqlTransaction and SqlCommand from the familiar System.Data.SqlClient namespace. For instance, the following code is executed when the Start Transaction button is clicked:

private void startTransactionButton_Click(  object sender, EventArgs e)
{  IsolationLevel isolation = new IsolationLevel();  switch (isolationLevelComboBox.SelectedIndex)  {    case 0: isolation = IsolationLevel.ReadUncommitted;        break;    case 1: isolation = IsolationLevel.ReadCommitted;        break;    case 2: isolation = IsolationLevel.RepeatableRead;        break;    case 3: isolation = IsolationLevel.Serializable;        break;    case 4: isolation = IsolationLevel.Snapshot;        break;  }  transaction = connection.BeginTransaction(isolation);  MessageBox.Show("Transaction has been started.", this.Text);
}


With this application, you can execute any SQL statement you prefer against the selected SQL Server database. For instance when using the Northwind database that is one of SQL Server's sample databases, you could test reading with statements like following:



SELECT *
FROM Customers


It is exciting to try to run this statement with different transaction isolation levels and note how locking changes. For instance when the repeatable read isolation mode is selected, the locks window will display many shared locks on the Customers table (Figure 3). In a similar fashion, if you execute an UPDATEstatement, you can see that exclusive locks will be placed on the table keys (see again Figure 2).






(Full Size Image)


Figure 3. On the right, many shared (S) locks can be seen after a simple SELECT statement is executed using the repeatable read transaction isolation level.



This is the code that is able to retrieve the locking information from the sys.dm_tran_locks view:



private void refreshButton_Click(object sender, EventArgs e)
{  SqlConnection connection =    new SqlConnection(connectionString);  string sql = "SELECT TOP 2000 [resource_type], " +      "[resource_description], [request_mode], " +      "[request_type], [request_status] " +      "FROM [sys].[dm_tran_locks] " +      "WHERE ([resource_type] <> 'DATABASE')";  SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);  DataTable locks = new DataTable();  adapter.Fill(locks);  // show the results on screen  locksDataGridView.DataSource = locks;    // free resources  adapter.Dispose();  connection.Dispose();
}


The actual SELECT statement executed to retrieve locking information is the following:



SELECT TOP 2000 [resource_type], [resource_description],
[request_mode], [request_type], [request_status]
FROM [sys].[dm_tran_locks]
WHERE ([resource_type] <> 'DATABASE')


Notice how the "TOP 2000" limitation is set as a safeguard against slowing down the database, if there are thousands of locks active currently. Furthermore, the resource type "DATABASE" is excluded from the results, as this lock type is always placed on a database level for each active connection to the database, and thus isn't relevant information for the purposes of this article.



Conclusion



Locking is an imperative feature in any database supporting multiple, simultaneous users. In SQL Server, locking is closely tied to transaction isolation levels. These two features together largely control how simultaneous reads and writes are coordinated in SQL Server.



In this article, you learned the basics of SQL Server 2008's locking, and saw how you can retrieve real-time locking information by querying a system view from your own code. An application similar to the one shown in this article is a great way to learn how SQL Server implements locks, as you can directly observe the locks in place after you've executed an SQL statement with a transaction isolation mode of your choice.



If you are interested in learning more about SQL Server's locking features, the Books Online (BOL) is an invaluable place to start and find reference information. When you study locking further, you can also learn about more advanced features such as lock escalation, lock partition and table hints with the WITHkeyword. But these are topics for another article.



Originally written by :Jani Jarvinen | Taken with thanks from :  CodeGuru