Tambayoyin Tambayoyi don Masu Haɓaka SQL: Tambayoyin SQL gama gari Q&A- Part 1

Bayyana menene SQL da rawar da yake takawa a cikin sarrafa bayanai

Amsa: SQL(Structured Query Language) harshe ne da ake amfani da shi don yin tambaya da sarrafa bayanai. Yana ba mu damar aiwatar da ayyuka kamar dawo da bayanai, sakawa, sabuntawa, da share bayanai daga ma'ajin bayanai. SQL kayan aiki ne na asali don hulɗa tare da sarrafa bayanai a yawancin Tsarin Gudanar da Bayanan Bayanai(DBMS).

 

Ta SQL, SELECT, INSERT, UPDATE, DELETE yaya za ku iya yin kuskure?

Amsa:

  • SELECT: Yana dawo da bayanai daga rumbun adana bayanai don debo bayanai daga tebur ɗaya ko fiye.
  • INSERT: Yana ƙara sabbin bayanai a cikin tebur a cikin ma'ajin bayanai.
  • UPDATE: Yana gyara data kasance a cikin tebur.
  • DELETE: Yana cire bayanai daga tebur.

 

Bayyana ra'ayoyin Primary Key kuma Foreign Key a cikin SQL

Amsa:

  • Primary Key : ginshiƙi ne ko saitin ginshiƙan da ake amfani da su don keɓance kowane layi a cikin tebur. Yana tabbatar da keɓancewa da ganewa don bayanan da ke cikin tebur.
  • Foreign Key: ginshiƙi ne ko saitin ginshiƙai a cikin tebur ɗaya wanda ke nufin maɓallin farko na wani tebur. Yana kafa dangantaka tsakanin tebur biyu a cikin bayanan.

 

Yadda ake amfani da WHERE sashe a cikin SELECT bayanin don tace bayanai daga tebur

Amsa: Yi amfani da WHERE sashe a cikin SELECT bayanin don fayyace sharuɗɗan da layuka dole ne su cika don haɗa su cikin sakamakon tambaya.

Misali:

SELECT * FROM Customers WHERE Country = 'USA';

 

Yadda ake amfani da JOIN bayanin don haɗa bayanai daga tebur da yawa a cikin SQL

Amsa: JOIN Ana amfani da bayanin don haɗa bayanai daga tebur biyu ko fiye bisa wani shafi mai alaƙa a tsakaninsu. Akwai nau'ikan nau'ikan nau'ikan JOIN, kamar INNER JOIN, LEFT JOIN, RIGHT JOIN,FULL JOIN.

Misali:

SELECT Orders.OrderID, Customers.CustomerName  
FROM Orders  
JOIN Customers ON Orders.CustomerID = Customers.CustomerID;  

 

Bayyana amfanin ginanniyar ayyuka a ciki SQL like SUM, COUNT, AVG, MAX, MIN

Amsa:

  • SUM: Yana ƙididdige jimlar ƙimar ginshiƙin lamba.
  • COUNT: Yana ƙidaya adadin layuka a cikin tebur ko adadin waɗanda ba mara amfani ba a cikin shafi.
  • AVG: Yana ƙididdige matsakaicin ƙimar ginshiƙin lamba.
  • MAX: Yana dawo da matsakaicin ƙima a cikin shafi.
  • MIN: Yana dawo da mafi ƙarancin ƙima a cikin shafi.

 

Yadda ake amfani da GROUP BY bayanin don rukunin bayanai a cikin SQL

Amsa: GROUP BY Ana amfani da bayanin don haɗa layuka masu ƙima iri ɗaya a cikin ginshiƙai ɗaya ko fiye da aiwatar da ayyukan jimillar a kansu.

Misali:

SELECT Country, COUNT(*) AS TotalCustomers  
FROM Customers  
GROUP BY Country;  

 

Yadda ake amfani da ORDER BY bayanin don warware bayanai a cikin SQL

Amsa: Ana amfani da bayanin da ya ba da umarni don warware sakamakon tambaya bisa ɗaya ko fiye da ginshiƙai. Tsohuwar tsari shine hawan hawan(ASC), amma ana iya amfani da DESC don saukowa tsari.

Misali:

SELECT * FROM Customers ORDER BY FirstName ASC, LastName DESC;

 

Yadda ake amfani da INSERT INTO bayanin don saka sabbin bayanai a cikin tebur

Amsa: Yi amfani da INSERT INTO bayanin don ƙara sabbin bayanai zuwa tebur a cikin bayanan

Misali:

INSERT INTO Customers(CustomerName, ContactName, Country)  
VALUES('John Doe', 'John Doe Jr.', 'USA');  

 

Yadda ake sabunta bayanai a cikin tebur ta amfani da UPDATE sanarwa a cikin SQL.

Amsa: Yi amfani da UPDATE bayanin don gyara bayanan da ke cikin tebur.

Misali:

UPDATE Customers  
SET ContactName = 'Jane Smith'  
WHERE CustomerID = 1;