SQL is one of the most common programming languages for creating and managing a database, as well as for performing various actions with the data itself.
As practice shows, it is quite easy to learn and makes the most of the standard vocabulary of the English language. Like any other programming language, SQL has its own logic and syntax, a set of basic commands and rules for their use.
SQL Commands Classification
All standard SQL commands can be considered based on their purpose. As the basis of the unofficial classification, you can take such sets as:
Commands for building queries.
Commands of built-in procedures and functions.
Trigger and system table commands.
Sets of combinations for working with date and string variables.
Commands for working with data and tables.
, SQL .
, , , . , , , , .
SQL , MicrosoftAccess. , , — MySQL, Internet. Oracle SQL.
SQL MicrosoftAccess
MicrosoftOffice. , MicrosoftAccess.
. SQL Access , , . , .
:
SELECT Pe_SurName
FROM Pherson
WHERE Pe_Name = '';
, , , Contacts.
SQL Access , .
SQL Oracle
Oracle – , , Microsoft SQL Server. Microsoft, - . , SQL Oracle SQL. , Oracle SQL, .
Oracle . , Oracle .
, , , , . Oracle . : SQL SQL, .
SELECTCONCAT(CONCAT(CONCAT(‘ ‘, sname), CONCAT(SUBSTR(fname, 0, 1), SUBSTR(otch, 0, 1))), CONCAT(‘ ‘, acceptdate)) FROM employees WHERE acceptdate > to_date(‘01.01.80′,’dd.mm.yyyy’);
, . , Microsoft SQL Server, SQL , .
SQL Internet
, , SQL . , , , .
, , , . , , SQL, , - MySQL.
SQL, , Microsoft tSQL Server.
SQL , . . , , :
$link = mysqli_connect('localhost', "root", '', 'tester');
if ( !$link ) die("Error");
$query = 'create table users(
login VARCHAR(20),
password VARCHAR(20)
)';
if (mysqli_query($link, $query)) echo " .";
elseecho " : ".mysqli_error();
mysqli_close($link);
"", : .
, MicrosoftSQLServer.
MicrosoftSQLServer
SQL. select SQL. .
, select SQL . , , , , , Person. , , - . SQL, , :
Select * from Person
Where P_BerthDay >= ‘01/01/2016’ and P_BerthDay<= ‘03/01/2016’
, , . , . , , :
SelectP_Name -
P_SurName -
P_Patronimic -
from Person
Where P_BerthDay >= ‘01/01/2016’ and P_BerthDay<= ‘03/01/2016’
-. , , , . SQL , , . , .
SQL
, . , . SQL :
Insert (. ).
Update (. ).
Delete (. ).
, . , , , , .
, MSSQL , .
, , - .
Insert
— Insert. .
Insert , .
Person. SQL, .
Insert into person
Select ‘’,’’,’’,’01/01/1988’
MS SQL SERVER . , , , . , , . :
Insertintoperson(P_Name, P_SurName ,P_BerthDay)
Values (‘’, ‘’,’02/11/1986’)
, null.
, Update SQL. , .
Update SQL . , , . . . , 5.
Update Person
Set P_BerthDay = ’02/10/1986’ where P_ID = 5
( ) , .
, .
SQL , . , , , .
, , . , , Excel. . . SQL , , SQLExec.
, Person. . Exec [ ] . :
CREATEPROCEDUREPrintPerson
@DB smalldatetime
@DE smalldatetime
AS
SET NOCOUNT ON;
SELECT * from Person
FROM HumanResources.vEmployeeDepartmentHistory
WHERE P_BerthDay >= @DB and P_BerthDay <= @DE
ANDEndDateISNULL;
GO
, .
.
MS SQL-, , , , . , . , .
SQL-. , , , .
SQL, , . .
, SQL , . .
:
CREATE TRIGGER Person_Insert
:
ONPerson
, ( ).
:
declare @ID int. @Date smalldatetime @nID int. @nDatesmalldatetime
:
DEclare cursor C1 for select P_ID, P_BerthDay from Inserted
DEclare cursor C2 for select P_ID, P_BerthDay from deleted
. , :
if @ID = @nID and @nDate = '01/01/2016'
begin
sMasseges ' . '
end
, , . , SQL SERVER:
altertablePERSONdisabletriggerall – , , , , altertablePERSONenabletriggerall – .
SQL , . SQL - .
: SQL , . , . , , , .
, , , , . SQL , , .
SQL , , -, . , .