preCharge Forums - View Single Post - Basics of sql
Thread: Basics of sql
View Single Post
Old 07-26-2006   #1 (permalink)
alan86
Junior Member
 
alan86's Avatar
 
Join Date: Jul 2006
Age: 23
Posts: 10
Send a message via ICQ to alan86 Send a message via MSN to alan86
Default Basics of sql

Table creation

Code:
CREATE TABLE table_name (name type [, name type [, ...]]);
SQL standard types are:


CHARACTER(n)String size n
n from 1 up to 15000



DATEDate in mm/gg/aa format



TIMEHour in hh:mm format



INTEGER(p)Integer number with p precision
p from 1 up to 45
p da 1 a 45


SMALLINTInteger number with precision 5
from -32768 up to 32767



INTEGERInteger number with precision 10
from -2.147.483.648 up to 2.147.483.647



DECIMAL(p,s)Decimal number with precision p and s cifre
p from 1 up to 45 and s from 0 up to p



REALReal number Numero reale con mantissa di precisione 7valore 0 oppure valore assoluto da 1E-38 a 1E+38


FLOATNumero reale con mantissa di precisione 15valore 0 oppure valore assoluto da 1E-38 a 1E+38


FLOAT(p)Numero reale con mantissa di precisione pp da 1 a 45



For example, to create a table with the data of dependents of a company we have to use this command:
Code:
CREATE TABLE tblDependents(
   Id     char(5),
   Surname   char(30),
   Name    char(20),
   FiscalCode char(16) not null,
   Engaged   date,
   Branch   smallint,
   Function  char(15),
   Level    smallint,
   Salary   integer,
   Address   char(25),
   Cap     char(5),
   City    char(20),
   );

Data manipulation

To insert a new row we use INSERT command:
Code:
INSERT INTO table_name(name) VALUES(value);
To modify one or more rows we use UPDATE command:
Code:
UPDATE table_name SET name = value [, name = value [, ...]] WHERE name = value [, name = value [, ...]]
To delete one ore more rows we use DELETE command:
Code:
DELETE FROM table_name WHERE name = value [, name = value [, ...]]
In our example we will have:
Code:
INSERT INTO tblDependents
(Id, Surname, Name, FiscalCode, Engaged, Branch, Function, Level, 
  Salary, Address, Cap, City)
VALUES ('AB541', 'Rossi', 'Paolo', 'RSSPLA65M20R341E', '09/15/1997', 3, 'Impiegato', 5, 
  890, 'via roma 34', '20100', 'Milano');
If we want to modify the level of dependent having id AA345:
Code:
UPDATE tblPersonale
  SET Livello = 6
  WHERE Id = 'AA345';
To delete dependend having id AQ123:
Code:
DELETE FROM tblPersonale
  WHERE Id = 'AQ123';
SELECT command

The general structure is the following:
Code:
SELECT name [, name [, ...]]
  FROM table_name [, table_name [, ...]]
  WHERE name = value
   [AND name = value]
For example, we can have the list with surname, name and fiscal code of all dependents with Impiegato function in this way:
Code:
SELECT Surname, Name, FiscalCode
  FROM tblDependent
  WHERE Function = 'Impiegato';
If we want all data of those who live in Milan:
Code:
SELECT *
  FROM tblDependent
  WHERE City = 'Milano'

If you'd like to have more information, you can visit [http://www.alangiacomin.net/forum/index.php?board=21.0]here[/url]
alan86 is offline   Reply With Quote

 
Breast Enlargement | Iphone 3g | Free Animated Greetings | Compare Mortgages | Anime