CSS Forums
Home   Beginner's Guide   Rules   Syllabus   Past Papers   Contact us  

Go Back   CSS Forums > The Central Superior Services Examination > Topics and Notes
User Name
Password

Topics and Notes Here you can share Notes/Topics that you consider important for the exam



Reply
 
Thread Tools Search this Thread
  #1  
Old 01-19-2008
Janeeta's Avatar
Janeeta Janeeta is offline
Senior Member
 
Join Date: Dec 2006
Location: Karachi
Posts: 127
Thanks: 27
Thanked 44 Times in 23 Posts
Janeeta is on a distinguished road
Thumbs up Sql

SQL(Structured query language)

· 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 works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc
Almost all modern Relational Database Management Systems like MS SQL Server, Microsoft Access, MSDE, Oracle, DB2, Sybase, MySQL, Postgres and Informix use SQL as standard database language


SQL is a keyword based language. Each statement begins with a unique keyword. SQL statements consist of clauses which begin with a keyword. SQL syntax is not case sensitive.


The other lexical elements of SQL statements are:
· names -- names of database elements: tables, columns, views, users, schemas; names must begin with a letter (a - z) and may contain digits (0 - 9) and underscore (_)
· literals -- quoted strings, numeric values, datetime values
· delimiters -- + - , ( ) = < > <= >= <> . * / || ? ;



Semicolon after SQL Statements?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.

Tables
A table is a set of columns and rows. Each column is referred to as a field. Each value in a field represents a single type of data. For example, a table might have three fields: name, city, and state. The table will consist of three columns: one for name, one for city, and one for state. For every row in the table, the name field contains the name, the city field contains the city, and the state field contains the state.

Every database consists of one or more tables, which store the database’s data/information

The database table columns (called also table fields) have their own unique names and have a pre-defined data types.
While table columns describe the data types, the table rows contain the actual data for the columns


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 data
base table


SQL Data Definition Language (DDL)

The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables.
The most important DDL statements in SQL are:
· CREATE TABLE - creates a new database table
· ALTER TABLE - alters (changes) a database table
· DROP TABLE - deletes a database table
· CREATE INDEX - creates an index (search key)
· DROP INDEX - deletes an index



SQL INSERT INTOThe INSERT INTO Statement

The INSERT INTO statement is used to insert new rows into a table.
Syntax
INSERT INTO table_nameVALUES (value1, value2,....)You can also specify the columns for which you want to insert data:
INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....)

Insert a New Row
This "Persons" table:
LastName FirstName Address City
Pettersen Kari Storgt 20 Stavanger

And this SQL statement:

INSERT INTO Persons VALUES ('Hetland', 'Camilla', 'Hagabakka 24', 'Sandnes')
Will give this result:
LastName FirstName Address C ity
Pettersen Kari Storgt 20 Stavanger
Hetland Camilla Hagabakka 24 Sandnes


Insert Data in Specified Columns
This "Persons" table:
LastName FirstName Address City
Pettersen Kari Storgt 20 Stavanger
Hetland Camilla Hagabakka 24 Sandnes
And This SQL statement:
INSERT INTO Persons (LastName, Address)VALUES ('Rasmussen', 'Storgt 67')Will give this result:
LastName FirstName Address City
Pettersen Kari Storgt 20 Stavanger
Hetland Camilla Hagabakka 24 Sandnes
Rasmussen Storgt 67


The Update Statement
The UPDATE statement is used to modify the data in a table.
Syntax
UPDATE table_nameSET column_name = new_valueWHERE column_name = some_value

Person:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Storgt 67


Update one Column in a Row
We want to add a first name to the person with a last name of "Rasmussen":
UPDATE Person SET FirstName = 'Nina'WHERE LastName = 'Rasmussen'Result:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Storgt 67

Update several Columns in a Row
We want to change the address and add the name of the city:
UPDATE PersonSET Address = 'Stien 12', City = 'Stavanger'WHERE LastName = 'Rasmussen'
Result:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Stien 12 Stavanger


The DELETE StatementThe DELETE statement is used to delete rows in a table.
Syntax
DELETE FROM table_nameWHERE column_name = some_value

Person:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Stien 12 Stavanger


Delete a Row
"Nina Rasmussen" is going to be deleted:
DELETE FROM Person WHERE LastName = 'Rasmussen'Result
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger


Delete All Rows
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_nameorDELETE * FROM table_nameSort the Rows


The ORDER BY clause is used to sort the rows.
Orders:
Company OrderNumber
Sega 3412
ABC Shop 5678
W3Schools 6798
W3Schools 2312

Example
To display the company names in alphabetical order:
SELECT Company, OrderNumber FROM OrdersORDER BY CompanyResult:
Company OrderNumber
ABC Shop 5678
Sega 3412
W3Schools 6798
W3Schools 2312


Example
To display the company names in reverse alphabetical order:
SELECT Company, OrderNumber FROM OrdersORDER BY Company DESCResult:
Company OrderNumber
W3Schools 6798
W3Schools 2312
Sega 3412
ABC Shop 5678

Column Name Alias
The syntax is:
SELECT column AS column_alias FROM table


Table Name Alias
The syntax is:
SELECT column FROM table AS table_alias

Example: Using a Column Alias
This table (Persons):
LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger

And this SQL:
SELECT LastName AS Family, FirstName AS NameFROM Persons
Returns this result:
Family Name
Hansen Ola
Svendson Tove
Pettersen Kari


Example: Using a Table AliasThis table (Persons):
LastName FirstName Address City
Hansen Ola Ti moteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger


And this SQL:
SELECT LastName, FirstNameFROM Persons AS EmployeesReturns this result:
Table Employees:
LastName FirstName
Hansen Ola
Svendson Tove
Pettersen Kari


SELECT STATEMENT COMING SOON
Reply With Quote
The Following 2 Users Say Thank You to Janeeta For This Useful Post:
irum (01-20-2008), Khushal (01-19-2008)

__________________
An expert is one who knows more and more about less and less.


  #2  
Old 01-19-2008
Khushal's Avatar
Khushal Khushal is offline
G R E N A D E
Moderator: Ribbon awarded to moderators of the forum - Issue reason: Khushal  moderates General ChatMedal of Appreciation: Medal of Appreciation - Issue reason: Appreciation
 
Join Date: Mar 2005
Location: On a blue chair in my hostel's room~
Posts: 594
Thanks: 27
Thanked 74 Times in 54 Posts
Khushal will become famous soon enoughKhushal will become famous soon enough
Send a message via Yahoo to Khushal
Default

Thanks alot Janeeta, you nearly covered up my 1st and 2nd monthly course in a single post, We've started studying DBMS this semester and this subject was kind of interesting yet demanding some practise.
Thanks for the good info! Thumbs up~
__________________
نہ تیرا پاکستان ہے , نہ میرا پاکستان ہے , یہ اس کاپاکستان ہے , جو صدرپاکستان ہے
Reply With Quote
The Following User Says Thank You to Khushal For This Useful Post:
Janeeta (04-12-2008)
  #3  
Old 04-19-2008
Janeeta's Avatar
Janeeta Janeeta is offline
Senior Member
 
Join Date: Dec 2006
Location: Karachi
Posts: 127
Thanks: 27
Thanked 44 Times in 23 Posts
Janeeta is on a distinguished road
Default

Thankx Khushak for appreciating me
if you find any problem in SQL fell free to ask as an OCP i ll try my best to solve your problem
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WEb Building GLossary Terms Janeeta Topics and Notes 0 01-19-2008 02:09 PM
Free Tests @ brainbench.com Satan References and Recommendations 19 05-14-2007 10:59 AM
C++ portability guide sibgakhan Topics and Notes 5 01-26-2007 08:52 PM
Data Base Design Glossary: Najabat Computers and Technology 0 11-27-2006 03:58 PM


All times are GMT +6. The time now is 04:38 AM.


vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd. Sponsors: ArgusVision Directory

Disclaimer: This is not the official website of Federal Public Service Commission Pakistan. This is a non-commercial website helping individuals who intend to join civil service of Pakistan. The material on this website is provided for informational purposes only. We do not claim that the site is an exhaustive compilation of information about Civil Service of Pakistan neither represent or endorse the accuracy or reliability of any information, content contained on, or linked, downloaded or accessed from any page of this website. These materials are intended, but not promised or guaranteed to be current, complete or up to date. However, honest efforts have been made to provide comprehensive information for the benefit of users. The documents and material displayed or mentioned on this site are not official copies. Please contact FPSC for updated rules and regulations governing CSS examination.