Tuesday, December 8, 2015

Introduction to C Language


C is one of the most popular computer language developed at AT&T’S Bell laboratories of USA in 1972 .It was developed by Dennis Ritchie. It is also called mid level language.
Today when the computer technology is on it's highest era and the advance programming languages like C++,C# and JAVA is very popular among developers many of us may think that C is now become less important. But this is not true since, C is still very popular and important language for it's following features.

Advantage Associated with C Language

  1. Simple to use and understand. You can later on migrate to C++, C# or java. Hence, preferring two-step learning process.
  2. C++,C# or java using oops technology that actually require core C language element.
  3. Operating system like window, Linux, UNIX is still written in C. And so if you are to extend any of above operating system to work with new devices you must need to write device driver program. And are exclusively written in C.
  4. C has best performance record. Because of highest execution among all other language (due to its verity of data type and powerful operator).
  5. Enormous electronic gadgets like mobile phone, digital camera, I-pod, microwaves, ovens, washing machine are using a microprocessor (chip) which contains an operating system and a program which are embedded in these devices which must have fast execution within limited amount of memory. And it is C who comes to show its smartness here.
  6. Professional 3D computer game like spaceship and firing bullet need speed to match player’s inputs and C is again hero here.
  7. Its structured, high level, machine independent language that provide programmer a freedom to portability facility.(One computer to another).
  8. C compilers combine the facility of an assembly language plus high level language. And hence capable to write both operating system and business pack. Many C compilers are itself written in C that is available in market.
  9. Another very important feature of C is its ability to extend itself .We can continuously add our own function to its library is convents.

Disadvantages Associated with C Language

  1. There is no strict type checking (for ex: we can pass an integer value for the floating data type).
  2. As the program extends it is very difficult to fix the bugs.
  3. There is no runtime checking.

Basic Structure of C program

  1. Documentation Section
  2. Link Section
  3. Definition Section
  4. Global Declaration Section
  5. -----------------------------------------------------------------
  6. main function section
  7. {
  8. //Declaration part
  9. //Executable part
  10. }
  11. -----------------------------------------------------------------
  12. Sub program section
  13. Function 1
  14. Function 2
  15. --
  16. -- //user defined function
  17. --
  18. Function n

Why C is called middle level language?


C is called middle-level language because it is actually bind the gap between a machine level language and high-level languages. User can use c language to do System Programming (for writing operating system) as well asApplication Programming (for generate menu driven customer billing system ). That's why it is called middle level language.
High level - Ada , Modula-2 , Pascal, COBOL, FORTRAN, BASIC
Middle level - Java, C++, C, FORTH, Macro-assemble
Low level - Assemble

Tuesday, December 1, 2015

Clustered Index & Nonclustered Index

Clustered Index 

A clustered index is an index that sorts and stores the data rows in the table based on their key values. Therefore, the data is physically sorted in the table when a clustered index is defined on it. Only one clustered index can be created per table. Therefore, you should build the clustered index on attributes that have a high percentage of unique values and are not modified often. In a clustered index, data is stored at the leaf level of the B- Tree.
 SQL Server performs the following steps when it uses a clustered index to search for a value:
SQL Server obtains the address of the root page from the sysindexes table, which is a system table containing the details of all the indexes in the database. The search value is compared with the key values on the root page. The page with the highest key value less than or equal to the search value is found. The page pointer is followed to the next lower level in the index. Steps 3 and 4 are repeated until the data page is reached. The rows of data are searched on the data page until the search value is found. If the search value is not found on the data page, no rows are returned by the query.

Nonclustered Index 

Similar to the clustered index, a nonclustered index also contains the index key values and the row locators that point to the storage location of the data in a table. However, in a nonclustered index, the physical order of the rows is not the same as the index order. Nonclustered indexes are typically created on columns used in joins and the WHERE clause. These indexes can also be created on columns where the values are modified frequently. SQL Server creates nonclustered indexes by default when the CREATE INDEX command is given. There can be as many as 999 nonclustered indexes per table. The data in a nonclustered index is present in a random order, but the logical ordering is specified by the index. The data rows may be randomly spread throughout the
table. The nonclustered index tree contains the index keys in a sorted order, with the leaf level of the index containing a pointer to the data page.
 SQL Server performs the following steps when it uses a nonclustered index to search for a value:

SQL Server obtains the address of the root page from the sysindexes table. The search value is compared with the key values on the root page. The page with the highest key value less than or equal to the search value is found. The page pointer is followed to the next lower level in the index. Steps 3 and 4 are repeated until the data page is reached. The rows are searched on the leaf page for the specified value. If a match is not found, the table contains no matching rows. If a match is found, the pointer is followed to the data page and the requested row is retrieved.

INDEX IN SQL

An index is an on-disk structure associated with a table or view that speeds retrieval of rows from the table or view. An index contains keys built from one or more columns in the table or view. These keys are stored in a structure (B-tree) that enables SQL Server to find the row or rows associated with the key values quickly and efficiently.
A table or view can contain the following types of indexes:
  • Clustered
    • Clustered indexes sort and store the data rows in the table or view based on their key values. These are the columns included in the index definition. There can be only one clustered index per table, because the data rows themselves can be sorted in only one order.
    • The only time the data rows in a table are stored in sorted order is when the table contains a clustered index. When a table has a clustered index, the table is called a clustered table. If a table has no clustered index, its data rows are stored in an unordered structure called a heap.
  • Nonclustered
    • Nonclustered indexes have a structure separate from the data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value.
    • The pointer from an index row in a nonclustered index to a data row is called a row locator. The structure of the row locator depends on whether the data pages are stored in a heap or a clustered table. For a heap, a row locator is a pointer to the row. For a clustered table, the row locator is the clustered index key.
    • You can add nonkey columns to the leaf level of the nonclustered index to by-pass existing index key limits, 900 bytes and 16 key columns, and execute fully covered, indexed, queries.