Welcome Guest, Not a member yet? Create Account  


SQL Syntax

#1
Question 

SQL Syntax
  • The syntax of a language describes the language elements.
  • SQL statements are somewhat like simple English sentences.
  • Keywords include SELECT, UPDATE, WHERE, ORDER BY, etc.
  • ANSI Standard SQL is the lingua franca for relational databases.




The SQL Syntax

SQL was designed to be entered on a console and results would display back to a screen.
Today, SQL is mostly used by programmers who use SQL inside their language to build applications that access data in a database.

Four fundamental operations that apply to any database are:


  1. Read the data  --  SELECT
  2. Insert new data  --  INSERT
  3. Update existing data  --  UPDATE
  4. Remove data  --  DELETE
Collectively these are referred to as CRUD (Create, Read, Update, Delete).
The general form for each of these 4 operations in SQL is presented next.



The SQL SELECT general form
  1. SELECT column-names
  2. FROM table-name
  3. WHERE condition
  4. ORDER BY sort-order
Example:

  1. SELECT FirstName, LastName, City, Country
  2. FROM Customer
  3. WHERE City = 'Paris'
  4. ORDER BY LastName



The SQL INSERT general form
  1. INSERT table-name (column-names)
  2. VALUES (column-values)
Example:
  1. INSERT Supplier (Name, ContactName, City, Country)
  2. VALUES ('Oxford Trading', 'Ian Smith', 'Oxford', 'UK')



The SQL UPDATE general form
  1. UPDATE table-name
  2. SET column-name = column-value
  3. WHERE condition
Example:
  1. UPDATE OrderItem
  2. SET Quantity = 2
  3. WHERE Id = 388



The SQL DELETE general form
  1. DELETE table-name
  2. WHERE condition
Example:
  1. DELETE Customer
  2. WHERE Email = 'alex@gmail.com'
[Image: 5c8f08b5fe55e12baae6fc54e46c343a.gif]




Users browsing this thread:
1 Guest(s)