Networking, Security & Cloud Knowledge

Showing posts with label Database - SQL. Show all posts
Showing posts with label Database - SQL. Show all posts

Friday, February 17, 2012

030 SQL commands

Introduction to SQL

  • SQL is a standard language for accessing and manipulating databases.
  • SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.
To build a web site that shows some data from a database, you will need the following:
  • An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
  • A server-side scripting language, like PHP or ASP
  • SQL
  • HTML / CSS

 

RDBMS :Relational Database Management System.


  •  RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access. 
  • The data in RDBMS is stored in database objects called tables. 
  • A table is a collection of related data entries and it consists of columns and rows.

SQL Command Summary:
CREATE DATABASE
CREATE DATABASE database_name

CREATE TABLE
CREATE TABLE table_name

(
column_name1 data_type,
column_name2 data_type,
column_name2 data_type,
...
)

UPDATE
UPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value

ALTER TABLE
ALTER TABLE table_name
WHERE SELECT Specific Column  ADD column_name datatype
OR

ALTER TABLE table_name
DROP COLUMN column_name

SELECT

SELECT column_name(s)
FROM table_name


SELECT ALL
SELECT * FROM table_name

SELECT DISTINCT
SELECT DISTINCT column_name(s)
FROM table_name

AND / OR
SELECT column_name(s)
FROM table_name
WHERE condition
AND | OR condition

BETWEENSELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN start_value AND end_value

ORDER BYSELECT column_name(s)
FROM table_name

ORDER BY column_name [ASC | DESC]

LIKESELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern

WHERE
SELECT column_name(s)DELETE
DELETE FROM table_name
WHERE column_name=specific_value
Note:
DELETE FROM table_name  OR  DELETE * FROM table_name
will delete entire table.

DROP Command

DROP DATABASE database_name
FROM table_name
WHERE column_name operator value

DROP TABLE
DROP TABLE table_name


SELECT TOP
SELECT TOP number | percent column_name(s)
FROM table_name