Friday, October 22, 2010

SQL Syntax

SQL Statements

Most of the actions you need to perform on a database are done with SQL statements.
The following SQL statement will select all the records in the "Persons" table:
SELECT * FROM Persons
Some database systems require a semicolon at the end of each SQL statement.


Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.

We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it.
SQL DML and DDL

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

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

The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:

* 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

ARTIKEL SOURCE : http://www.w3schools.com

Read More......

Sunday, February 10, 2008

Introduction to SQL

SQL is an acronym for structured query language and it is a language designed specifically for accessing databases to read or write data. SQL databases are the most popular type since it is incredibly versatile and easy to use. Most people use them for websites, although they are also used for non-web applications.



Several popular SQL packages exist, but the most popular is mySQL, which is open source. Microsoft also provides SQL server software, but it is rather expensive. For security and cost reasons, mySQL is probably the best choice if you plan to use SQL for web design.

With SQL, you can create as many databases as you like. Inside of a database, there are objects called tables. Inside of tables, there are objects called rows that have columns containing different types of information. For example, you could design a table so that each row has a column with an integer, some text, and a category. Designing a table is like designing a class in C++ or Java, since you are essentially creating variables that can be different for each individual instance of an object.

The variety of SQL commands gives the software a lot of capibilities. You can, for example, query a database and have it only return rows in a table that have a certain value for their category. This way, you can easily access information of varying types within a single table. It also allows you to create dynamic pages using PHP. Instead of hardcoding links to every single object in a table, like you would have to do in HTML, you can write code the queries the table for certain values and automatically creates links. In the end, this can save the website designer thousands of hours of work.

What is SQL?

* SQL stands for Structured Query Language
* SQL allows you to access a database
* SQL is an ANSI standard computer language
* SQL can execute queries against a database
* SQL can retrieve data from a database
* SQL can insert new records in a database
* SQL can delete records from a database
* SQL can update records in a database
* SQL is easy to learn

SQL is a Standard - BUT....

SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.

Unfortunately, there are many different versions of the SQL language, but to be in compliance with the ANSI standard, they must support the same major keywords in a similar manner (such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others).

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!


SQL Data Manipulation Language (DML)

SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records.

These query and update commands together form the Data Manipulation Language (DML) part of SQL:

  • SELECT - extracts data from a database table
  • UPDATE - updates data in a database table
  • DELETE - deletes data from a database table
  • INSERT INTO - inserts new data into a database table

Read More......