Computer Applications

Tuesday, January 5, 2010

C++ Tutorial

C++ is an object oriented language, which combines the best of the structured programming techniques of C, thus making it a very powerful language.
Example:
# include
int main()
{
std:: cout << “My first C++ program ” << std::endl;
return 0;
}

Output Is: My first C++ program

C++ is a superset of C; therefore most of C language constructs apply in C++ as well. A program in C++ can be written in both C style and Object Oriented style.

SQL (Structured Query Language).

SQL is a standard language for accessing databases.

1. SQL stands for Structured Query Language
2. SQL lets you access and manipulate databases
3. SQL is an ANSI (American National Standards Institute) standard

SQL can do

It can execute queries against a database
It can retrieve data from a database
It can insert records in a database
It can update records in a database
It can delete records from a database
It can create new databases
It can create new tables in a database
It can create stored procedures in a database
It can create views in a database
It can set permissions on tables, procedures, and views

SQL can be divided into two parts:
1.The Data Manipulation Language (DML)
2. The Data Definition Language (DDL).

DML

The query and update commands form the DML part of SQL:
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database

DDL

CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index

Creating Table in SQL

Each row represents one piece of data, and each column can be thought of as representing a component of that piece of data. So, for example, if we have a table for recording customer information, then the columns may include information such as First Name, Last Name, Address, City, Country, Birth Date, and so on.

SYNTAX

CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )

Example

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)

Insert Values into Table in SQL

One is to insert it one row at a time, the other is to insert multiple rows at a time. Let's first look at how we may INSERT data one row at a time.

Syntax

INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)

Example

INSERT INTO Store_Information (store_name, Sales, Date)
VALUES ('Los Angeles', 900, 'Jan-10-1999')

Select from Table

A common use is to select data from the tables located in a database. Immediately, we see two keywords: we need to SELECT information FROM a table.

Syntax

SELECT "column_name" FROM "table_name"

Example

SELECT store_name FROM Store_Information
Result:
store_name
Los Angeles
San Diego
Los Angeles
Boston

Update Command

   We can use the UPDATE command for modifying the data.

Syntax:

UPDATE "table_name" SET "column_1" = [new value] WHERE {condition}

Example:

UPDATE Store_Information SET Sales = 500 WHERE store_name = "Los Angeles"AND Date = "Jan-08-1999".

Delete Command

    We may wish to use a query to remove records from a table.

Syntax:

DELETE FROM "table_name" WHERE {condition}

Example :

DELETE FROM Store_Information WHERE store_name = "Los Angeles"