INSERT INTO

INSERT INTO bayonoti jadvalga yangi yozuvlarni qo'shish uchun ishlatiladi.

SU

SQL INSERT INTO Bayonoti

INSERT INTO bayonoti jadvalga yangi yozuvlarni qo'shish uchun ishlatiladi.

INSERT INTO Sintaksisi

INSERT INTO bayonotini ikki usulda yozish mumkin:

  1. Ustun nomlari va qo'shiladigan qiymatlarni belgilash:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
  1. Agar siz jadvaldagi barcha ustunlar uchun qiymatlarni qo'shayotgan bo'lsangiz, SQL so'rovida ustun nomlarini ko'rsatishingiz shart emas. Ammo, qiymatlarning tartibi jadvaldagi ustunlar tartibiga mos kelishini ta'minlang. Bunda INSERT INTO sintaksisi quyidagicha bo'ladi:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

Demo Ma'lumotlar Bazasi

Quyida misollarda ishlatiladigan Customers jadvalidan tanlov keltirilgan:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland

INSERT INTO Misoli

Quyidagi SQL bayonoti "Customers" jadvaliga yangi yozuv qo'shadi:

Misol O'zingizning SQL serveringizni oling Yangi mijoz qo'shing:

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

"Customers" jadvalidagi tanlov endi quyidagicha ko'rinadi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
92CardinalTom B. ErichsenSkagen 21Stavanger4006Norway

Siz CustomerID maydoniga hech qanday raqam qo'shmaganimizni sezdingizmi? CustomerID ustuni avtomatik ravishda o'suvchi (auto-increment) maydon bo'lib, yangi yozuv jadvalga kiritilganda avtomatik ravishda yaratiladi.

Faqat Belgilangan Ustunlarga Ma'lumot Qo'shish

Shuningdek, faqatgina muayyan ustunlarga ma'lumot qo'shish ham mumkin.

Quyidagi SQL bayonoti yangi yozuv qo'shadi, ammo faqat "CustomerName", "City" va "Country" ustunlarida ma'lumot kiritadi (CustomerID avtomatik yangilanadi):

Misol

INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');

"Customers" jadvalidagi tanlov endi quyidagicha ko'rinadi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
92CardinalnullnullStavangernullNorway

Bir Nechta Qator Qo'shish

Bitta bayonotda bir necha qatorlarni qo'shish ham mumkin.

Bir nechta ma'lumot qatorlarini qo'shish uchun, biz bir xil INSERT INTO bayonotini bir nechta qiymatlar bilan ishlatamiz:

Misol

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES
('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway'),
('Greasy Burger', 'Per Olsen', 'Gateveien 15', 'Sandnes', '4306', 'Norway'),
('Tasty Tee', 'Finn Egan', 'Streetroad 19B', 'Liverpool', 'L1 0AA', 'UK');

Har bir qiymat to'plamini vergul bilan ajratishingizga ishonch hosil qiling ,.

"Customers" jadvalidagi tanlov endi quyidagicha ko'rinadi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
89White Clover MarketsKarl Jablonski305 - 14th Ave. S. Suite 3BSeattle98128USA
90Wilman KalaMatti KarttunenKeskuskatu 45Helsinki21240Finland
91WolskiZbyszekul. Filtrowa 68Walla01-012Poland
92CardinalTom B. ErichsenSkagen 21Stavanger4006Norway
93Greasy BurgerPer OlsenGateveien 15Sandnes4306Norway
94Tasty TeeFinn EganStreetroad 19BLiverpoolL1 0AAUK

Ushbu sahifada

Xato haqida xabar berish