Search This Blog

Friday, August 6, 2010

Enable Secerity tab in XP

1. Go to run promt

2.Type gpedit.msc

3.Group policy window will open

4.In that window u can see computer configuration

5.Under that option u can see windows settings.

6.Click that option and click security settings.

7.Now u can see one folder in the name of

local policies .click that option

8.Now u can see security option . click that.

9.Now u can see more options in one window.

10. Now press "N" and search where is

NETWORK ACCESS: SHARING AND SECURITY FOR LOCAL ACCOUNTS option.

11.Nlick that option. and new window will pop up

12.In that window u can see one drop down box.

now u should select classic: local users

authendicate as themselves.



now close all the windows .open one folder select properties . now am sure u can see security tab....

Tuesday, July 27, 2010

About GIMP

Introduction to GIMP

GIMP is an acronym for GNU Image Manipulation Program. It is a freely distributed program for such tasks as photo retouching, image composition and image authoring.
It has many capabilities. It can be used as a simple paint program, an expert quality photo retouching program, an online batch processing system, a mass production image renderer, an image format converter, etc.
GIMP is expandable and extensible. It is designed to be augmented with plug-ins and extensions to do just about anything. The advanced scripting interface allows everything from the simplest task to the most complex image manipulation procedures to be easily scripted.
GIMP is written and developed under X11 on UNIX platforms. But basically the same code also runs on MS Windows and Mac OS X.

Features and Capabilities

This is only a very quickly thrown together list of GIMP features. .
  • Painting
    • Full suite of painting tools including Brush, Pencil, Airbrush, Clone, etc.
    • Sub-pixel sampling for all paint tools for high quality anti-aliasing
    • Extremely powerful gradient editor and blend tool
    • Supports custom brushes and patterns
  • System
    • Tile based memory management so image size is limited only by available disk space
    • Virtually unlimited number of images open at one time
  • Advanced Manipulation
    • Full alpha channel support
    • Layers and channels
    • Multiple Undo/Redo (limited only by diskspace)
    • Editable text layers
    • Transformation tools including rotate, scale, shear and flip
    • Selection tools including rectangle, rounded rectangle, ellipse, free, fuzzy
    • Foreground extraction tool
    • Advanced path tool doing bezier and polygonal selections.
    • Transformable paths, transformable selections.
    • Quickmask to paint a selection.
  • Extensible
    • A Procedural Database for calling internal GIMP functions from external programs as in Script-fu
    • Advanced scripting capabilities (Scheme, Python, Perl)
    • Plug-ins which allow for the easy addition of new file formats and new effect filters
    • Over 100 plug-ins already available
  • Animation
    • Load and save animations in a convenient frame-as-layer format
    • MNG support
    • Frame Navigator (in GAP, the GIMP Animation Package)
    • Onion Skin (in GAP, the GIMP Animation Package)
    • Bluebox (in GAP, the GIMP Animation Package)
  • File Handling
    • File formats supported include bmp, gif, jpeg, mng, pcx, pdf, png, ps, psd, svg, tiff, tga, xpm, and many others
    • Load, display, convert, save to many file formats
    • SVG path import/export
  • Much, much more!

GIMP Feature Overview

Customizable Interface

# Each task requires a different environment and GIMP allows you to customize the view and behavior the way you like it. Starting from the widget theme, allowing you to change colors, widget spacings and icon sizes to custom tool sets in the toolbox. The interface is modulized into so called docks, allowing you to stack them into tabs or keep them open in their own window. Pressing the tab key will toggle them hidden.
GIMP features a great fullscreen mode allowing you to not only preview your artwork but also do editing work while using the most of your screen estate.

Photo Enhancement

Numerous digital photo imperfections can be easily compensated for using GIMP. Fix perspective distortion caused by lens tilt simply choosing the corrective mode in the transform tools. Eliminate lens' barrel distortion and vignetting with a powerful filter but a simple interface.
# The included channel mixer gives you the flexibility and power to get your B/W photography stand out the way you need.
#

Digital Retouching

GIMP is ideal for advanced photo retouching techniques. Get rid of unneeded details using the clone tool, or touch up minor details easily with the new healing tool. With the perspective clone tool, it's not difficult to clone objects with perspective in mind just as easily as with the orthogonal clone.

Hardware Support

GIMP includes a very unique support for various input devices out of the box. Pressure and tilt sensitive tablets, but also a wide range of USB or MIDI controllers. You can bind often-used actions to device events such as rotating a USB wheel or moving a MIDI controller's slider. Change the size, angle or opacity of a brush while you paint, bind your favorite scripts to buttons. Speed up your workflow!
#

File Formats

# The file format support ranges from the common likes of JPEG (JFIF), GIF, PNG, TIFF to special use formats such as the multi-resolution and multi-color-depth Windows icon files. The architecture allows to extend GIMP's format capabilities with a plug-in. You can find some rare format support in the GIMP plugin registry.
Thanks to the transparent virtual file system, it is possible to load and save files to from remote locations using protocols such as FTP, HTTP or even SMB (MS Windows shares) and SFTP/SSH.
To save disk space, any format can be saved with an archive extension such as ZIP, GZ or BZ2 and GIMP will transparently compress the file without you needing to do any extra steps.

Supported Platforms

  • GNU/Linux (i386, PPC)
  • Microsoft Windows (XP, Vista)
  • Mac OS X
  • Sun OpenSolaris
  • FreeBSD

Synaptic package manager

Synaptic package manager E-mail
Synaptic is a graphical package management program for apt. It provides the same features as the apt-get command line utility with a GUI front-end. What does that mean? It’s a program that allows you to easily install other programs (and any software required to run them) in Linux. You can also use it to update and/or remove software.
Synaptic is included with a number of the popular versions of Linux, including: Debian, Fedora and Ubuntu.
  1. Launch Synaptic by selecting System -> Administration -> Synaptic Package Manger.
  2. Enter your administrative password when prompted…
  3. and the main Synaptic window will appear. From here you can view all of the available applications to install by using the left column. Use the Search button in the top menu to help find programs you’re interested in. You don’t need to know a programs name to locate it, you can use keywords (such as email, RSS, browser, games etc).
  4. click to enlarge
  5. When you find something you want to install, select it by clicking the box next to it and then Mark for Installation. Note: if the box is already “filled in”, the program is already installed.
  6. google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
  7. If the program you’ve chosen to install requires additional software in order to work, it will be automatically detected and included in the list of things to install. Click the Mark button to continue.
  8. If you want to install more than one program, repeat the above two steps. When you’re ready, click the Apply button from the top menu.
  9. Now click Apply in the Summary window.
  10. All of the required files will now be downloaded.
  11. The installation will begin as soon as the files have finished downloading. If you want to watch the installation progress, click Details.
  12. click to enlarge
  13. Once everything is finished, click Close.
  14. click to enlarge
  15. You can find your newly installed programs in their respective locations.

Friday, July 23, 2010

VISUAL C++ PROGRAMMING-INTRODUCTION


 
1. Define AppWizard
Appwizard is a code generator used to create a working skeleton for the windows with the  features  source code and  features specified through dialog boxes.

2. What are the types of mapping modes?

  • MM_HIMETRIC
  • MM_ANISOTROPIC
  • MM_ISOTROPIC

3. What is the use of setMap Mode command?
It is used to return the previous mapping mode and sets the mapping mode specified in the parameter.

4. What is resole font?
The system font is the font that windows uses by default for text string like strings in titke bars, menus and dialog boxes. The system font is a razor font which means that the characters are defined as blocks of pixels.

5. What is the use of get system metrics function?

This function retrieves  information about the size of various graphical item in windows such as icons, occurs, title bars and scroll bars. This function is an important function for achieving device independent graphical outline in the program.

6. What is system modal dialog?
The 16-bit versions of windows support a special kind of modal dialog called a system modal dialog, which prevents the user from switching to another application

7. Mention some of the GDI derived classes?
  • Cbitmap
  • Cbrush
  • Cfont
  • Cpalette
  • Cpen

8. What are dialog controls?
A dialog control contains a number of elements called controls. These includes Edit controls, buttons ,list boxes ,static text, Etc.

9. Explain the display context classes CclientDC and CwindowDC?
Windows client area excludes the border, the caption bar,and the menu bar.If we construct an object of class Cclient DC,the point (0,0) is at the upper-left corner of the client area.

10. What is the state of the device context?

The current state of the device context includes the following:
Attached GDI drawing objects such as pens,brushes and fonts.
The  mapping mode that  determines the scale of items when they are drawn.

11. What are GDI objects?
A window GDI object type is represented by an MFC library class.CGD iobject is the abstract base class for the GDI object classes.

12. What is Project?
Project is a collection of interrelated source files that are compiled and linked to make up an executable windows based program or a DLL.

13. What is Make File?
A make file stores compiler and linker options and express all the interrelationships among source files.

14. What is a make program?
A make program reads the make files and then invokes a compiler , assembler, resource compiler and linker to produce the final output, which is generally an executable file.

15. What is Class Wizard?
 Class Wizard is a program that’s accessible from visual C++’s view menu.
Class wizard writes the prototypes,the function bodies and the code to link the windows message to the function.

16. What is an application framework?
Application framework is an integraterd collection of object oriented software copmponents that offers all that’s needed for a generic application.

17. Mention the two building options ?

  • Win32 Debug
  • Win32 Release

18. Mention the two types of fonts.
 Two  types of fonts are       
·        Device-independent fonts
·        Device-dependent fonts.

19. List the types of video cards  used to display the colors
  • 256 color video card
  • 16 bit color video card
  • 24 bit color video card
20. Give the unique features of 24-bit color video cards:
High –end cards support 24-bit color .this 24-bit capability enables the display of more than 16.7 million pure colors.The RGB macro allows you to specify the exact colors you want.

VISUAL C++ PROGRAMMING-INTRODUCTION


 
1. Define AppWizard
Appwizard is a code generator used to create a working skeleton for the windows with the  features  source code and  features specified through dialog boxes.

2. What are the types of mapping modes?

  • MM_HIMETRIC
  • MM_ANISOTROPIC
  • MM_ISOTROPIC

3. What is the use of setMap Mode command?
It is used to return the previous mapping mode and sets the mapping mode specified in the parameter.

4. What is resole font?
The system font is the font that windows uses by default for text string like strings in titke bars, menus and dialog boxes. The system font is a razor font which means that the characters are defined as blocks of pixels.

5. What is the use of get system metrics function?

This function retrieves  information about the size of various graphical item in windows such as icons, occurs, title bars and scroll bars. This function is an important function for achieving device independent graphical outline in the program.

6. What is system modal dialog?
The 16-bit versions of windows support a special kind of modal dialog called a system modal dialog, which prevents the user from switching to another application

7. Mention some of the GDI derived classes?
  • Cbitmap
  • Cbrush
  • Cfont
  • Cpalette
  • Cpen

8. What are dialog controls?
A dialog control contains a number of elements called controls. These includes Edit controls, buttons ,list boxes ,static text, Etc.

9. Explain the display context classes CclientDC and CwindowDC?
Windows client area excludes the border, the caption bar,and the menu bar.If we construct an object of class Cclient DC,the point (0,0) is at the upper-left corner of the client area.

10. What is the state of the device context?

The current state of the device context includes the following:
Attached GDI drawing objects such as pens,brushes and fonts.
The  mapping mode that  determines the scale of items when they are drawn.

11. What are GDI objects?
A window GDI object type is represented by an MFC library class.CGD iobject is the abstract base class for the GDI object classes.

12. What is Project?
Project is a collection of interrelated source files that are compiled and linked to make up an executable windows based program or a DLL.

13. What is Make File?
A make file stores compiler and linker options and express all the interrelationships among source files.

14. What is a make program?
A make program reads the make files and then invokes a compiler , assembler, resource compiler and linker to produce the final output, which is generally an executable file.

15. What is Class Wizard?
 Class Wizard is a program that’s accessible from visual C++’s view menu.
Class wizard writes the prototypes,the function bodies and the code to link the windows message to the function.

16. What is an application framework?
Application framework is an integraterd collection of object oriented software copmponents that offers all that’s needed for a generic application.

17. Mention the two building options ?

  • Win32 Debug
  • Win32 Release

18. Mention the two types of fonts.
 Two  types of fonts are       
·        Device-independent fonts
·        Device-dependent fonts.

19. List the types of video cards  used to display the colors
  • 256 color video card
  • 16 bit color video card
  • 24 bit color video card
20. Give the unique features of 24-bit color video cards:
High –end cards support 24-bit color .this 24-bit capability enables the display of more than 16.7 million pure colors.The RGB macro allows you to specify the exact colors you want.

Windows Programming


1. What is Windows Programming?
Windows Programming uses GUI conc~pt. It is an event­driven programming. An Application Window will respond to the events. by generating a message by, the Operating. System. It uses. graphics for organizing user workspace. Programs that run within Windows also use GUI. (e.g.):. Word, Excel . These application programs use some built-in functions present in API.

2. Differentiate between DOS based programming. &Window based programming.        .
DOS based Programming
1. Hardware Dependent
2. Activated when the OS is called

             3. Never calls the program running under it .
Window Based Programming
1. Hardware'lndependent
2. Activated when it receives the message
3. Can call a program running, under it

3. List the main header files in windows programming?
- WINDOWS.H
- WINDEF.H
- WINNT.H
- WINBASE.H
- WINUSER.H
- WINGDI.H
4. What is an API?
API stands for Application Programming Interface. API is a set of commands that interfaces program with processor. It is a set of routines, protocols and tools for developing a software application. API programs are written in C Language. .

5. Write the ways of implementing API?
API. can be implemented by using libraries(win32.dll)
- kernel
- User
- GDI.

6. What are the uses of kernel, user and GDI Libraries?
- The kernel is responsible for management operation, context switching, and process   loading
- The user is used for manipulating the user interface.
 - Graphical Device Interface (GDI) for graphical output and store of images.


7. Name any platform independent API?
Platform independent API is portable to any OS.
There are two platforms independent APIs
i)WIN16
ii)WIN32

8. What is Hungarian Notation?
            The naming convention for windows programming is called as Hungarian Notation . In this notation the variable names are preceded with key letters. The key letters describe the  type of data the variable represents.
e.g.,                            
                           h       handle

sz       character string terminated by zero


9. What are the steps required to create a window?
 The steps required to create a window are,
a.Registering Window Class

b.Create a Window
c.MessageLoop
d.Window Procedure
10. How to register a window class?
            Before creating an application window. the window class must be registered. Window class is registered by calling register class. This f'unction requires a single parameter, which is a pointer to structure of, type WNDCLASS

11. What is a window class?
A Window is always created using a window Class. The window, class identifies the window procedure that processes messages to the window. The Window class
defines the window procedure and some other characterizing of window that created based on the class

12. Define Message Loop?
When a windows program begins execution, a window creates a "message queue" for the program; this message queue stores messages to all the windows a program might create. A windows application includes is short check of code called the message loop to retrieve those messages from the queue and dispatch them to the appropriate window procedure. A simple message to enter of one function call to each of three functions, GetMessage, Translate Message and Dispatch Message


13. What is the use of Translate Message?
A Message Loop include Translate message, if the message loop receive character input from the keyboard, the system generates virtual key messages CW_ KEYDOWN and  WM_ KEYUP each time the user process a key.

14. What is the use of Dispatch Message?
The Dispatch Message function sends a: message to the window procedure associated with the window handle specified in the MSG structure.

15. What are the actions of windows procedure?
The windows procedure is the function named Wndproc. The Window procedure deteimines what the window displays in its client area the window responds to user input.

A window procedure is defined as,
LRESULT CALLBACK WndProc(HWND hwnd , UINT  message, WPARAM wParam, LPARAM IParam)

16. What is the value returned from GetMessage?
Get message returns a non-zero value for anything other than WM_QUIT message. A WM_QUIT message causes Get message to return zero.
17. What IS WM_PAINT message?
This message informs when a part or all of the windows client area is "invalid" and must be "updated" which means that it must be redrawn or "painted".

18. How does a client area become invalid?
The client area is invalid when

- The window is created first
- The window is resized
- The window is minimized
- The window is moved around the screen so that they overlap .
19. How does WMPAINT message is processed?
              
    WMPAINT processing almost always begins with a call to Begin paint.
                          hdcBeginPaint (hwnd,&ps);
and ends with a call to EndPaint
                              EndPaint (hwnd,&Ps);
BeginPaint erases the backround, EndPaint releases the device context handle.
20. What is WM_DESTROY message?

WM_DESTROY message indicates that a window is.in the process of destroying a window based on a command from the,user; The message is a result of the user clicking on the close button or selecting close from the program's System message.

21. How the program is terminated?
When the PostQuit message function is invoked it inserts a WM_QUIT message in the Program's message queue. GetMessage returns zero for WM_QUIT message. This causes WinMain to drop put of the Message Loop. The program then returns msgWParam, The program tenninated.

22. What is GDI?
The Graphics Device Interface (GDI) provides functions .and related structures that an application can use to generate graphical output for displays, printers and other devices.

23. Define Scroll bar and what are are the messages generated?
A Scroll bar is a rectangle that contains a scroll bar and has  direction arrows at both ends. The user can click the arrows, click on .the gray area between the arrows, or drag the Scrollbox to scroll the scroll bar's parent window. The messages are WM_HSCROLL and WM_VSCROLL


24.What is a keyboard accelerator? \Y!1at are the messages generated?
A Keystroke or combination of keystrokes that sends a command message to the specified application window is called a keyboard accelerator.

The messages generated are;

- WM_COMMAND
- WM _KEYUP
- WM _KEYDOWN
- WM _SYSKEYUP
- WM_SYSCOMMAND
- WM _SYSKEYDOWN

25. What is a menu? What are its types?
A Menu is a GUI, which contains a list of menu items. The types of menu are,        

1. System Menus
2. Popup Menu
3. Dropdown Menu

26. What are the functions of messagebox function?
Message Box function is used to deliver text output to user. This function creates a window, but, it is a special purpose window of limited flexibility. The message box window has a title bar with a close button an optional icon, one or more lines of text.

27. What are queued and non queued messages?
The.queued messages are those that are placed in a programs message queue by windows. The queued messages are posted to a message queue. The non queued messages are the  results of calls by windows directly to the window procedure.
28. When does the window procedure receives a WM_PAINT message?
a)When a previous hidden area of the. window is brought into view when ,a user     
       moves a window, or uncovers a window ­
b) The user resizes the window (if the window class style has set bits)    .
c) The program user the scroll window or scroll  dc function to scroll part of its
       client area. .
             d) The program uses the invalidaterect or invalidates RG  function.

29.What are the various groups into which GDI function calls are grouped?       

a)Function that get and release a device context
b)Function that obtain information about device context
c) Functions that draw something
d) Functions that set and get attributes of the device  context
e)Functions that work with  GDI objects

30. What are the seven functions supported by windows 98 to draw lines?

- Lineto  -  draws a straight line
- Poly line and poly line co -  draw a series of connected straight lines
- Polyline - Draws multiple poly line
- Arc - Draws eliptical1ine
- Poly Bezier and polybezierlo - draw Bezier splines
- Arc to and angle arc - draw elliptical line
- Poly draw  - draws a series of connected Hnes and. Bezier splines

Windows Programming

1. What is Windows Programming?
Windows Programming uses GUI conc~pt. It is an eventdriven programming. An Application Window will respond to the events. by generating a message by, the Operating. System. It uses. graphics for organizing user workspace. Programs that run within Windows also use GUI. (e.g.):. Word, Excel . These application programs use some built-in functions present in API.

2. Differentiate between DOS based programming. &Window based programming. .
DOS based Programming
1. Hardware Dependent
2. Activated when the OS is called

3. Never calls the program running under it .
Window Based Programming
1. Hardware'lndependent
2. Activated when it receives the message
3. Can call a program running, under it

3. List the main header files in windows programming?
- WINDOWS.H
- WINDEF.H
- WINNT.H
- WINBASE.H
- WINUSER.H
- WINGDI.H
4. What is an API?
API stands for Application Programming Interface. API is a set of commands that interfaces program with processor. It is a set of routines, protocols and tools for developing a software application. API programs are written in C Language. .

5. Write the ways of implementing API?
API. can be implemented by using libraries(win32.dll)
- kernel
- User
- GDI.

Friday, July 16, 2010

SQL Tutorial


What is SQL?

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

What Can SQL do?

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

SQL is a Standard - BUT....

Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.
However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.
Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!

Using SQL in Your Web Site
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

RDBMS stands for 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 collections of related data entries and it consists of columns and rows.


Database Tables

A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.
Below is an example of a table called "test":

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

The table above contains three records (one for each person) and five columns (P_Id, LastName, FirstName, Address, and City).

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 "Test" table:

SELECT * FROM test

Keep in Mind That...

SQL is not case sensitive

Semicolon after SQL Statements?

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

The SQL SELECT Statement

The SELECT statement is used to select data from a database.
The result is stored in a result table, called the result-set.

SQL SELECT Syntax

SELECT column_name(s)
FROM table_name

And

SELECT * FROM table_name

An SQL SELECT Example

The "Test" table:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Now we want to select the content of the columns named "LastName" and "FirstName" from the table above.
We use the following SELECT statement:
Now we want to select the content of the columns named "LastName" and "FirstName" from the table above.

We use the following SELECT statement:

SELECT LastName,FirstName FROM Test
The result-set will look like this:

LastName FirstName
Hansen Ola
Svendson Tove
Pettersen Kari

SELECT * Example

Now we want to select all the columns from the "Test" table.
We use the following SELECT statement:

SELECT * FROM Test

Tip: The asterisk (*) is a quick way of selecting all columns!

The result-set will look like this:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

The SQL SELECT DISTINCT Statement

In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (different) values.

SQL SELECT DISTINCT Syntax

SELECT DISTINCT column_name(s)
FROM table_name

SELECT DISTINCT Example
The "test" table:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Now we want to select only the distinct values from the column named "City" from the table above.
We use the following SELECT statement:

SELECT DISTINCT City FROM test

The result-set will look like this:
City
Sandnes
Stavanger

The WHERE Clause

The WHERE clause is used to extract only those records that fulfill a specified criterion.
SQL WHERE Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name operator value

WHERE Clause Example



The "test" table:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
Now we want to select only the test living in the city "Sandnes" from the table above.
We use the following SELECT statement:
SELECT * FROM test
WHERE City='Sandnes'

The result-set will look like this:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes

Quotes Around Text Fields

SQL uses single quotes around text values (most database systems will also accept double quotes).
Although, numeric values should not be enclosed in quotes.
For text values:
This is correct:

SELECT * FROM test WHERE FirstName='Tove'

This is wrong:

SELECT * FROM test WHERE FirstName=Tove

For numeric values:

This is correct:

SELECT * FROM test WHERE Year=1965

This is wrong:

SELECT * FROM test WHERE Year='1965'

Operators Allowed in the WHERE Clause

With the WHERE clause, the following operators can be used:
Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN If you know the exact value you want to return for at least one of the columns
Note: In some versions of SQL the <> operator may be written as !=


The AND & OR Operators

The AND operator displays a record if both the first condition and the second condition is true.
The OR operator displays a record if either the first condition or the second condition is true.

AND Operator Example

The "test" table:



P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger



Now we want to select only the test with the first name equal to "Tove" AND the last name equal to "Svendson":

We use the following SELECT statement:
SELECT * FROM test
WHERE FirstName='Tove'
AND LastName='Svendson'

The result-set will look like this:

P_Id LastName FirstName Address City
2 Svendson Tove Borgvn 23 Sandnes

OR Operator Example

Now we want to select only the test with the first name equal to "Tove" OR the first name equal to "Ola":

We use the following SELECT statement:

SELECT * FROM test
WHERE FirstName='Tove'
OR FirstName='Ola'

The result-set will look like this:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes

Combining AND & OR

You can also combine AND and OR (use parenthesis to form complex expressions).

Now we want to select only the test with the last name equal to "Svendson" AND the first name equal to "Tove" OR to "Ola":

We use the following SELECT statement:

SELECT * FROM test WHERE
LastName='Svendson'
AND (FirstName='Tove' OR FirstName='Ola')

The result-set will look like this:

P_Id LastName FirstName Address City
2 Svendson Tove Borgvn 23 Sandnes

The ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set by a specified column.
The ORDER BY keyword sort the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.

SQL ORDER BY Syntax

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC

ORDER BY Example

The "test" table:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Tom Vingvn 23 Stavanger

Now we want to select all the test from the table above, however, we want to sort the test by their last name.

We use the following SELECT statement:

SELECT * FROM test
ORDER BY LastName

The result-set will look like this:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
4 Nilsen Tom Vingvn 23 Stavanger
3 Pettersen Kari Storgt 20 Stavanger
2 Svendson Tove Borgvn 23 Sandnes

ORDER BY DESC Example



Now we want to select all the test from the table above, however, we want to sort the test descending by their last name.

We use the following SELECT statement:

SELECT * FROM test
ORDER BY LastName DESC

The result-set will look like this:

P_Id LastName FirstName Address City
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Tom Vingvn 23 Stavanger
1 Hansen Ola Timoteivn 10 Sandnes


The INSERT INTO Statement

The INSERT INTO statement is used to insert a new row in a table.

SQL INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two forms.
The first form doesn't specify the column names where the data will be inserted, only their values:

INSERT INTO table_name
VALUES (value1, value2, value3,...)
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

SQL INSERT INTO Example
We have the following "test" table:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
Now we want to insert a new row in the "test" table.
We use the following SQL statement:

INSERT INTO test
VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger')

The "test" table will now look like this:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 Stavanger

Insert Data Only in Specified Columns

It is also possible to only add data in specific columns.
The following SQL statement will add a new row, but only add data in the "P_Id", "LastName" and the "FirstName" columns:

INSERT INTO test (P_Id, LastName, FirstName)
VALUES (5, 'Tjessem', 'Jakob')

The "test" table will now look like this:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 Stavanger
5 Tjessem Jakob




The UPDATE Statement
The UPDATE statement is used to update existing records in a table.

SQL UPDATE Syntax

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

Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!

SQL UPDATE Example

The "test" table:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 Stavanger
5 Tjessem Jakob




Now we want to update the person "Tjessem, Jakob" in the "test" table.

We use the following SQL statement:

UPDATE test
SET Address='Nissestien 67', City='Sandnes'
WHERE LastName='Tjessem' AND FirstName='Jakob'

The "test" table will now look like this:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 Stavanger
5 Tjessem Jakob Nissestien 67 Sandnes

SQL UPDATE Warning

Be careful when updating records. If we had omitted the WHERE clause in the example above, like this:
UPDATE test
SET Address='Nissestien 67', City='Sandnes'

The "test" table would have looked like this:

P_Id LastName FirstName Address City
1 Hansen Ola Nissestien 67 Sandnes
2 Svendson Tove Nissestien 67 Sandnes
3 Pettersen Kari Nissestien 67 Sandnes
4 Nilsen Johan Nissestien 67 Sandnes
5 Tjessem Jakob Nissestien 67 Sandnes

The DELETE Statement

The DELETE statement is used to delete rows in a table.

SQL DELETE Syntax

DELETE FROM table_name
WHERE some_column=some_value

Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
SQL DELETE Example

The "test" table:

P_Id
LastName
FirstName
Address
City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 Stavanger
5 Tjessem Jakob Nissestien 67 Sandnes
Now we want to delete the person "Tjessem, Jakob" in the "test" table.
We use the following SQL statement:
DELETE FROM test
WHERE LastName='Tjessem' AND FirstName='Jakob'
The "test" table will now look like this:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
4 Nilsen Johan Bakken 2 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_name

or

DELETE * FROM table_name
Note: Be very careful when deleting records. You cannot undo this statement!