Go to content Go to navigation Go to search

Basic SQL Statements

December 8th, 2008 by Gabriel

Basic SQL Statements :

SQL is used to query the database which are almost same for SQL Server, MS Access, Oracle and MySQL.
There are four types of basic queries :-

SELECT
INSERT
UPDATE
DELETE
ORDER BY

Different combination of parameters can be passed to a query.

1] SELECT :-

its the most common SQL statement using which data can be selected from database and the output is returned to user.The result is

stored in a result table, called the result-set.SQL is not case sensitive. SELECT is the same as select.
Here is a simple example -

select name, bdate from user;
this will return all names and bdates from the table user.

select * from user;
this will return all records of user table.

select * from user where name=’john’;
this will return all records in which name = john

select * from user where name=’john’ OR name=’paul’ OR bdate=01012007
this way you can add multiple filtering using “OR” , “AND” clause.

2] INSERT :-

it is used to take the data input from user and insert it into table of the database. Data can be taken from any form or it can be

directly inserted using query.It is used to insert a new row in a table.
Simple example-
Insert into Table1 (FirstName, LastName, Phone) Values (’Gabriel’, ‘R’, ‘1112222′);

3] UPDATE :-

Using Update, we edit / modify any exisiting table. Either all the rows can be updated, or a subset may be chosen using a condition.
Simple example -
Update Table1 Set name=@FirstName, LastName=@LastName, Phone=@Phone where id=@ID

WHERE clause us very important in Update query. If you don’t use WHERE then it will update all existing records in the table.

4] DELETE :-

It is used to delete rows in a table. It also uses WHERE claue. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted.
Here is an example of a Delete statement-

Delete From Table1 where ID=10

it will delete all records in which ID = 10

5] Order By Clauses :-

It is used to sort the output returned by a query. Using this clause, you can sort by any field in the table.
Example -
Select * from Table1 Order By name

This will list all returned records sorted by Name alphabetically.

‘ASC’ (ascending order) or ‘DESC’ (descending order) can be included in Orderby query to sort the output in ascending or descending order respectively.
Like -

Select * from Table1 Order By name DESC

Basic security precautions

October 12th, 2008 by Gabriel

Some basic security policies that a Web Administrator should have to consider are -

1. who/which user is allowed to use the system
2. when the user is allowed to use it
3. which user granted which level of access
4. procedures for granting access to the system
5. remote and local access methods
6. system monitoring
7. suspected security breaches

If you don’t have a clear picture of what is permitted, you can never be sure when a violation has occurred.

General security precautions to take -

1. Limit the number of login accounts available on the machine and delete inactive users.
2. The Crack programs help to detect poorly chosen passwords hence force the people to use strong             passwords who have login privileges.
3. Unused services should be turned off. For e.g. if FTP is no longer needed then it should be stopped.
4. Check system regularly for suspicious activity.
5. Make sure that permissions are set correctly on system files.