Sintaxa SQL

postat acum 4 ani de Stefanescu Mihai in categorie SQL

Ca si in orice limbaj de programare si SQL are un anumit set de reguli ce trebuiesc respectate, acest set de reguli se numeste Sintaxa. In acest articol am sa va dau cateva exemple de sintaxa SQL.

Pentru inceput am sa va prezint operatiile de baza din SQL care incep toate cu urmatoarele cuvinte cheie SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW si toate aceste expresii se termina cu punct si virgula (;).

Un lucru important ce trebuie tinut minte este faptul ca SQL este case insensitive, ceea ce inseamna ca SELECTinseamna acelasi lucru cu select, dar numele tabelelor sunt case sensitive.

Expresie Select:

SELECT coloana_1, coloana2....coloana_n FROM   nume_tabel;

 Expresie select distinct:

SELECT DISTINCT coloana_1, coloana2....coloana_n FROM   nume_tabel;

Expresie select cu clauza Where:

SELECT coloana_1, coloana_2....coloana_n FROM   nume_tabel WHERE  conditie;

Clauzele AND si OR:

SELECT coloana_1, coloana_2....coloana_n FROM nume_tabel WHERE  Conditie 1 {AND|OR} Conditie 2;

Clauza IN:

SELECT coloana_1, coloana_2....coloana_n FROM nume_tabel WHERE  nume_coloana IN (val-1, val-2,...val-N);

Clauza BETWEEN:

SELECT coloana_1, coloana_2....coloana_n
FROM   nume_tabel
WHERE  nume_coloana BETWEEN valoare_1 AND valoare_2;

Clauza LIKE:

SELECT coloana_1, coloana_2....coloana_n
FROM   nume_tabel
WHERE  nume_coloana LIKE { Tipar_Cautat };

Clauza Order By:

SELECT coloana_1, coloana_2....coloana_N
FROM   nume_tabel
WHERE  Conditie
ORDER BY nume_coloana {ASC|DESC};

Clauza Group By:

SELECT SUM(nume_coloana)FROM   nume_tabel
WHERE  Conditie GROUP BY nume_coloana;

Clauza Count:

SELECT COUNT(nume_coloana) FROM   nume_tabel WHERE  Contitie;

Clauza Having:

SELECT SUM(nume_coloana) FROM   nume_tabel WHERE Conditie
GROUP BY nume_coloana HAVING (conditie / functie aritmetica);

 Expresie Create Table:

CREATE TABLE numele_tabelului(
coloana_1 tip_de_date,
coloana_2 tip_de_date,
coloana_3 tip_de_date,
.....
coloana_n tip_de_date,
PRIMARY KEY( una sau mai multe coloane )
);

 Expresie Drop Table:

DROP TABLE nume_tabel;

Expresie de CREATE INDEX:

CREATE UNIQUE INDEX nume_index ON nume_tabel ( coloana_1, coloana_2,...coloana_N);

Expresie DROP INDEX:

ALTER TABLE nume_tabel DROP INDEX nume_index;

Expresie Truncate Table:

TRUNCATE TABLE nume_tabel;

Expresie Alter Table:

ALTER TABLE nume_tabel {ADD|DROP|MODIFY} nume_coloana {tip_date};

Expresie Alter Rename:

ALTER TABLE nume_tabel RENAME TO nume_nou_tabel;

Expresie Insert INTO:

INSERT INTO nume_tabel( coloana_1, coloana_2....coloana_N)
VALUES ( valoare_1, valoare_2....valoare_N);

Expresie UPDATE:

UPDATE nume_tabel SET coloana_1 = valoare_1, coloana_2 = valoare_2....coloana_N=valoare_N
[ WHERE  Conditie ];

Expresie DELETE:

DELETE FROM nume_tabel WHERE  {Conditie};

Expresie CREATE DATBASE:

CREATE DATABASE nume_baza_de_date;

Expresie DROP DATABASE:

DROP DATABASE nume_baza_de_date;

Expresie USE:

USE nume_baza_de_date;

Expresie COMMIT:

COMMIT;

Expresie ROLLBACK:

ROLLBACK;

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de g la data de 13.05.2019
Hello, yup this paragraph is genuinely fastidious and I have learned lot of things from it about blogging. thanks.
Comentariu postate de how to download minecraft free la data de 14.05.2019
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Comentariu postate de mojang minecraft download la data de 15.05.2019
Just desire to say your article is as astounding. The clarity in your post is simply nice and i can assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the rewarding work.
Comentariu postate de minecraft download free la data de 15.05.2019
Wow, fantastic blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is fantastic, as well as the content!
Comentariu postate de minecraft download free pc la data de 16.05.2019
Definitely consider that that you said. Your favourite reason seemed to be at the net the easiest thing to have in mind of. I say to you, I definitely get irked whilst other folks consider issues that they plainly don't realize about. You controlled to hit the nail upon the highest and outlined out the entire thing with no need side effect , other folks could take a signal. Will probably be back to get more. Thank you
Comentariu postate de free minecraft la data de 17.05.2019
Very rapidly this site will be famous amid all blogging and site-building viewers, due to it's pleasant articles or reviews