Inserare de informatii (INSERT INTO)

Stefanescu Mihai 2 years ago SQL
Acest articol face parte din cursul Toate lectiile SQL. Te poti inscrie la acest curs aici!

Comanda INSERT INTO este folosita la inserarea de noi informatii (randuri sau tupluri) intr-un anumit tabel al bazei de date.


Exista doua sintaxe pentru inserarea de informatii:

INSERT INTO numeTabel (Coloana1, Coloana2, Coloana3,...ColoanaN)]  
VALUES (Valoare1, Valoare2, Valoare3,...ValoareN);

Aici, Coloana1, Coloana2, ColoanaN sunt numele date coloanelor cand ati creat tabelul.

Sintaxa de mai sus se foloseste atunci cand doriti sa adaugati informatii decat in anumite coloane din tabel si sa le omiteti pe altele.

Asigurativa ca datele din sectiunea VALUES() sunt trecuta in ordinea coloanelor din INSERT INTO.Sintaxa de mai jos se foloseste atunci cand doriti sa completati toate coloanele tabelei:

INSERT INTO numeTabel VALUES (Valoare1,Valoare2,Valoare3,...ValoareN);


Iata un exemplu concret de INSERT:

INSERT INTO angajati (ID, Nume , Varsta, Adresa, Salariu)
VALUES (1, 'Mihai', 22, 'Bucuresti str. xxx', 5000.00 );

INSERT INTO angajati (ID, Nume , Varsta, Adresa, Salariu)
VALUES (2, 'Alex', 27, 'Bucuresti str. yyy', 2000.00 );

Puteti adauga informatii in baza de date si cu cealalta sintaxa:

INSERT INTO angajati 
VALUES (2, 'Alex', 27, 'Bucuresti str. yyy', 2000.00 );

Codurile de mai sus au adaugat urmatoarele date in tabelul angajati:

SQL> SELECT * FROM angajati
| ID | Nume     | Varsta | Adresa             | Salariu  |
|  1 | Mihai    |     22 | Bucuresti str. xxx |  5000.00 |
|  2 | Alex     |     27 | Bucuresti str. yyy |  2000.00 |

Inserarea in tabel a informatiilor din alt tabel

Se poate sa inserati date dintr-un tabel in altul cu un simplu INSERT ca in exemplul de mai jos:

INSERT INTO primulTabel [(Coloana1, Coloana2, ... ColoanaN)] 
VALUES(SELECT Coloana1, Coloana2, ...ColoanaN FROM alDoileaTabel WHERE conditie)


Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.

Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

Gluxcg # 1 month ago order fenofibrate 200mg without prescription <a href="">tricor brand</a> how to get tricor without a prescription
ansial sin receta en Bélgica # 1 month ago Woah! I'm really loving the template/theme of this website. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between user friendliness and visual appearance. I must say that you've done a excellent job with this. Also, the blog loads very quick for me on Opera. Exceptional Blog!
Nagmqx # 1 month ago order ketotifen generic <a href="">doxepin us</a> tofranil pill
Yolrhf # 1 month ago cost acarbose 25mg <a href="">order acarbose</a> buy griseofulvin
Mxmpem # 1 month ago purchase mintop generic <a href="">ed pills otc</a> buy ed medication online
Ifzhmp # 4 weeks ago aspirin 75mg usa <a href="">buy aspirin 75 mg pill</a> imiquimod drug
Nklqwz # 3 weeks ago florinef us <a href="">buy fludrocortisone online cheap</a> buy imodium 2 mg online cheap
Qtpdkc # 3 weeks ago purchase duphaston generic <a href="">where can i buy januvia</a> cheap jardiance 25mg
Bzfhrz # 2 weeks ago prasugrel 10mg price <a href="">cost dimenhydrinate 50mg</a> order tolterodine 2mg online
Iakowg # 2 weeks ago order monograph 600mg online cheap <a href="">pletal price</a> generic cilostazol
Rwyujf # 2 weeks ago buy ferrous sulfate paypal <a href="">order betapace generic</a> betapace 40mg tablet
Ksynxx # 2 weeks ago pyridostigmine uk <a href="">pyridostigmine 60mg for sale</a> maxalt cost
indicatie van benzac te koop in België # 1 week ago Very nice post. I just stumbled upon your blog and wanted to say that I've truly enjoyed browsing your blog posts. In any case I will be subscribing to your rss feed and I hope you write again soon!
Nfcihv # 1 week ago betahistine 16 mg over the counter <a href="">purchase zovirax sale</a> buy probenecid generic
Svfgox # 1 week ago order zovirax online cheap <a href="">rivastigmine 6mg tablet</a> exelon without prescription
Ldzqvm # 1 week ago purchase micardis <a href="">order hydroxychloroquine 200mg pill</a> buy molnunat for sale
Wssddh # 6 days ago cenforce 50mg over the counter <a href="">buy generic cenforce</a> buy aralen
consulta con un médico para obtener una receta de acyclovir 60 tablets en Guayaq # 4 days ago My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using Movable-type on several websites for about a year and am nervous about switching to another platform. I have heard excellent things about Is there a way I can transfer all my wordpress content into it? Any kind of help would be greatly appreciated!
Vvndqf # 3 days ago cefdinir 300 mg cost <a href="">cefdinir canada</a> purchase lansoprazole online
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

🔖 Bookmarks
✨ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

🌪️ Discord
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.