A cikin SQL, wadanne nau'ikan joins
kuka yi amfani da su, kuma ku bayyana yadda suke aiki?
Amsa:
INNER JOIN
: Yana dawo da layuka tare da bayanai masu dacewa daga tebur biyu.LEFT JOIN
: Yana dawo da duk layuka daga teburin hagu da layuka masu dacewa daga teburin dama.RIGHT JOIN
: Yana dawo da duk layuka daga teburin dama da layuka masu dacewa daga teburin hagu.FULL JOIN
: Yana dawo da duk layuka daga tebur biyu, gami da layuka marasa dacewa.
Bayyana ra'ayoyin ACID a cikin SQL da rawar da suke takawa wajen sarrafa ma'amala
Amsa: ACID yana nufin Atomicity, Consistency, Isolation, Durability
. Waɗannan mahimman kaddarori ne a cikin sarrafa ma'amala a cikin SQL:
Atomicity
yana tabbatar da cewa an yi cikakken sarrafa ciniki ko ba a sarrafa shi gaba ɗaya.Consistency
yana tabbatar da cewa dole ne bayanai su bi ƙayyadaddun ƙa'idodi, ƙuntatawa, da yanayi.Isolation
yana tabbatar da cewa ma'amaloli na lokaci guda ba sa tsoma baki tare da juna.Durability
yana tabbatar da cewa da zarar an gama ciniki, ana adana canje-canjen da ke cikin ma'ajin bayanai amintacce da dindindin.
Menene bambanci tsakanin ROW_NUMBER(), RANK(), DENSE_RANK()
ayyuka a cikin SQL?
Amsa: ROW_NUMBER(), RANK(), DENSE_RANK()
duk ana amfani da su don ƙididdige layuka a cikin sakamakon tambaya, amma suna da bambance-bambance masu zuwa:
ROW_NUMBER()
: Sanya lambobi masu ci gaba zuwa layuka a cikin sakamakon tambaya, ba tare da la'akari da kwafi ba.RANK()
: Sanya lambobi zuwa layuka a cikin sakamakon tambaya kuma ya tsallake lamba ta gaba idan akwai alaƙa.DENSE_RANK()
: Sanya lambobi zuwa layuka a cikin sakamakon tambaya kuma baya tsallake lamba na gaba idan akwai alaƙa.
Yadda ake amfani da su window functions
a cikin SQL, kuma ba da misali.
Amsa: Window functions
ba da izinin yin lissafi akan saitin layuka masu alaƙa ba tare da canza babban sakamakon tambaya ba. Misali, zamu iya amfani da ayyukan taga don lissafin jimlar gudu ko dawo da manyan layuka N a cikin saitin sakamako.
SELECT ProductID, UnitPrice,
SUM(UnitPrice) OVER(ORDER BY ProductID) AS RunningTotal
FROM Products;
Yadda ake amfani da maganganu na yau da kullun a cikin SQL don daidaita tsarin
Amsa: Kalmomi na yau da kullun a cikin SQL ana amfani da su don hadadden binciken ƙirar rubutu. Ana amfani da su sau da yawa tare da LIKE
mai aiki ko ayyuka kamar REGEXP_LIKE
(a cikin Oracle) ko REGEXP_MATCHES
(a cikin PostgreSQL).
SELECT * FROM Employees WHERE LastName LIKE '%son%';
Yadda ake amfani da ayyukan JSON a cikin SQL don aiki tare da bayanan JSON
Amsa: Ayyukan JSON a cikin SQL suna ba da damar yin tambaya, sakawa, sabuntawa, da share bayanai a tsarin JSON a cikin ma'ajin bayanai.
Misali, zamu iya amfani da ayyuka kamar JSON_VALUE, JSON_QUERY, JSON_MODIFY(a cikin SQL Server), ko masu aiki kamar ->, ->>, #>, #>>, da sauransu(a cikin PostgreSQL) don sarrafa kayan JSON.
SELECT JSON_VALUE(CustomerInfo, '$.Name') AS CustomerName
FROM Customers;
Dabarun ci-gaba don haɓaka tambayar SQL da daidaita ayyukan bayanai
Amsa: Don inganta tambayoyin SQL da aikin bayanai, za mu iya amfani da dabaru kamar:
- Yin amfani da fihirisa don ginshiƙan da ake tambaya akai-akai.
- Haɓaka
JOIN
daWHERE
ƙa'idodi don ingantaccen maido da bayanai. - Yin amfani da ayyukan taga da shafi idan ya cancanta.
- Gujewa
SELECT
* don dawo da ginshiƙai masu mahimmanci kawai. - Amfani da alamun tambaya a wasu lokuta.
- Tabbatar da daidaita bayanai da cire kwafi.
- Yin amfani da kayan aikin sa ido na aiki don waƙa da daidaita bayanan bayanai.
Bayyana yadda ake amfani da SET
ayyuka (UNION, INTERSECT, EXCEPT)
a cikin SQl
Amsa: Ana amfani da SET
ayyuka don haɗawa da sarrafa saitin sakamako na tambayoyi daban-daban. (UNION, INTERSECT, EXCEPT)
UNION
: Yana haɗa sakamakon tambayoyi biyu ko fiye a cikin saitin bayanai ɗaya kuma yana cire kwafi.INTERSECT
Yana dawo da layuka da suka bayyana a duka saitin sakamakon tambaya.EXCEPT
Yana dawo da layuka da suka bayyana a saitin sakamako na farko amma ba a na biyu ba.
Yadda ake amfani da ayyukan tambaya kamar LEAD, LAG, FIRST_VALUE, LAST_VALUE
a cikin SQL
Amsa: Ayyukan tambaya kamar LEAD, LAG, FIRST_VALUE, LAST_VALUE
ana amfani da su don dawo da ƙima daga layuka masu alaƙa a cikin sakamakon tambaya iri ɗaya.
LEAD
: Yana samun darajar shafi daga jere na gaba a cikin sakamakon tambaya.LAG
: Yana samun ƙimar shafi daga layin da ya gabata a cikin sakamakon tambaya.FIRST_VALUE
: Yana dawo da ƙimar farko na shafi a cikin sakamakon tambaya.LAST_VALUE
: Yana dawo da ƙimar ƙarshe na shafi a cikin sakamakon tambaya.