Database
 sql >> Datenbank >  >> RDS >> Database

Die 115 wichtigsten SQL-Interviewfragen, die Sie im Jahr 2022 vorbereiten müssen

RDBMS ist eine der derzeit am häufigsten verwendeten Datenbanken und daher SQL-Kenntnisse sind in den meisten Berufsbildern unverzichtbar. In diesem Artikel zu SQL-Interviewfragen stelle ich Ihnen die am häufigsten gestellten Fragen zu SQL (Structured Query Language) vor. Dieser Artikel ist der perfekte Leitfaden für Sie, um alle Konzepte im Zusammenhang mit SQL, Oracle, MS SQL Server und MySQL-Datenbanken zu lernen. Unser Artikel zu den 65 wichtigsten SQL-Interviewfragen ist die zentrale Quelle von wo aus Sie Ihre Vorbereitung auf das Vorstellungsgespräch verbessern können.

Möchten Sie sich weiterbilden, um in Ihrer Karriere voranzukommen? Sehen Sie sich die Top Trending Technologies an .

Fangen wir an!

SQL-Interviewfragen

  1. Was ist der Unterschied zwischen SQL und MySQL?
  2. Was sind die verschiedenen Teilmengen von SQL?
  3. Was meinen Sie mit DBMS? Welche Arten gibt es?
  4. Was meinen Sie mit Tabelle und Feld in SQL?
  5. Was sind Verknüpfungen in SQL?
  6. Was ist der Unterschied zwischen den Datentypen CHAR und VARCHAR2 in SQL?
  7. Was ist der Primärschlüssel?
  8. Was sind Beschränkungen?
  9. Was ist der Unterschied zwischen DELETE- und TRUNCATE-Anweisungen?
  10. Was ist ein eindeutiger Schlüssel?

F1. Was ist der Unterschied zwischen SQL und MySQL?

SQL vs. MySQL

SQL MySQL
SQL ist eine Standardsprache, die für Structured Query Language steht und auf der basiert Englische Sprache MySQL ist ein Datenbankverwaltungssystem.
SQL ist der Kern der relationalen Datenbank, die für den Zugriff auf und die Verwaltung der Datenbank verwendet wird

MySQL ist ein RDMS (Relational Database Management System) wie SQL Server, Informix usw.

F2. Was sind die verschiedenen Teilmengen von SQL?

  • Data Definition Language (DDL) – Damit können Sie verschiedene Operationen auf der Datenbank ausführen, wie CREATE-, ALTER- und DELETE-Objekte.
  • Data Manipulation Language (DML) – Ermöglicht den Zugriff auf und die Bearbeitung von Daten. Es hilft Ihnen beim Einfügen, Aktualisieren, Löschen und Abrufen von Daten aus der Datenbank.
  • Data Control Language (DCL) – Damit können Sie den Zugriff auf die Datenbank steuern. Beispiel – Zugriffsberechtigungen erteilen, widerrufen.

F3. Was meinst du mit DBMS? Welche Arten gibt es?

Ein Datenbankverwaltungssystem (DBMS ) ist eine Softwareanwendung, die mit dem Benutzer, Anwendungen und der Datenbank selbst interagiert, um Daten zu erfassen und zu analysieren. Eine Datenbank ist eine strukturierte Sammlung von Daten.

Ein DBMS ermöglicht es einem Benutzer, mit der Datenbank zu interagieren. Die in der Datenbank gespeicherten Daten können geändert, abgerufen und gelöscht werden und können von beliebigem Typ sein, wie Zeichenfolgen, Zahlen, Bilder usw.

Es gibt zwei Arten von DBMS:

  • Relationales Datenbankverwaltungssystem :Die Daten werden in Relationen (Tabellen) gespeichert. Beispiel – MySQL.
  • Nicht relationales Datenbankverwaltungssystem :Es gibt kein Konzept von Relationen, Tupeln und Attributen. Beispiel – MongoDB

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.

Q4. Was ist RDBMS? Wie unterscheidet es sich von DBMS?

Ein Managementsystem für relationale Datenbanken (RDBMS) ist eine Reihe von Anwendungen und Funktionen, die es IT-Experten und anderen ermöglichen, relationale Datenbanken zu entwickeln, zu bearbeiten, zu verwalten und mit ihnen zu interagieren. Die meisten kommerziellen Managementsysteme für relationale Datenbanken verwenden die Structured Query Language (SQL), um auf die Datenbank zuzugreifen, die in Form von Tabellen gespeichert ist.
Das RDBMS ist das am weitesten verbreitete Datenbanksystem in Unternehmen auf der ganzen Welt. Es bietet ein stabiles Mittel zum Speichern und Abrufen großer Datenmengen.

Datenbanken enthalten im Allgemeinen Sammlungen von Daten, auf die zugegriffen werden kann und die in anderen Anwendungen verwendet werden können. Die Entwicklung, Verwaltung und Nutzung von Datenbankplattformen werden alle von einem Datenbankmanagementsystem unterstützt.

Ein relationales Datenbankverwaltungssystem (RDBMS) ist eine Art Datenbankverwaltungssystem (DBMS), das Daten in einer zeilenbasierten Tabellenstruktur speichert, die verwandte Datenkomponenten verknüpft. Ein RDBMS enthält Funktionen, die die Sicherheit, Genauigkeit, Integrität und Konsistenz der Daten gewährleisten. Dies ist nicht dasselbe wie der Dateispeicher, der von einem Datenbankverwaltungssystem verwendet wird.

Im Folgenden finden Sie einige weitere Unterscheidungen zwischen Datenbankverwaltungssystemen und relationalen Datenbankverwaltungssystemen:

Die Anzahl der Benutzer, die das System nutzen dürfen
Ein DBMS kann jeweils nur einen Benutzer verwalten, während ein RDBMS zahlreiche Benutzer verwalten kann.
Hardware- und Softwarespezifikationen
Im Vergleich zu einem RDBMS erfordert ein DBMS weniger Software und Hardware.
Menge an Informationen
RDBMS können beliebige Datenmengen verarbeiten, von winzig bis riesig, während DBMS auf kleine Mengen beschränkt sind.
Die Struktur der Datenbank
Daten werden in einem DBMS in einem hierarchischen Format gespeichert, während ein RDBMS eine Tabelle mit Überschriften verwendet, die als Spaltennamen und Zeilen dienen, die die zugehörigen Werte enthalten.
Umsetzung des ACID-Prinzips
Das Konzept der Atomizität, Konsistenz, Isolation und Dauerhaftigkeit (ACID) wird von DBMSs nicht zur Datenspeicherung verwendet. RDBMS hingegen verwenden das ACID-Modell, um ihre Daten zu organisieren und Konsistenz sicherzustellen.
Verteilte Datenbanken
Ein DBMS bietet keine vollständige Unterstützung für verteilte Datenbanken, während ein RDBMS dies tut.
Verwaltete Programme
Ein DBMS konzentriert sich auf die Verwaltung von Datenbanken, die innerhalb des Computernetzwerks und der Systemfestplatten vorhanden sind, während ein RDBMS dabei hilft, die Beziehungen zwischen den darin enthaltenen Datentabellen zu verwalten.
Normalisierung von Datenbanken wird unterstützt
Ein RDBMS kann normalisiert werden, aber ein DBMS kann nicht normalisiert werden.

F5. Was ist ein Self-Join?

Ein Self-Join ist ein Join-Typ, der verwendet werden kann, um zwei Tabellen zu verbinden. Infolgedessen handelt es sich um eine unäre Beziehung. Jede Zeile der Tabelle ist mit sich selbst und allen anderen Zeilen derselben Tabelle in einem Self-Join verbunden. Daher wird ein Self-Join meistens verwendet, um Zeilen aus derselben Datenbanktabelle zu kombinieren und zu vergleichen.

F6. Was ist die SELECT-Anweisung?

Ein SELECT-Befehl ruft null oder mehr Zeilen aus einer oder mehreren Datenbanktabellen oder -ansichten ab. Der häufigste DML-Befehl (Data Manipulation Language) ist in den meisten Anwendungen SELECT. SELECT-Abfragen definieren eine Ergebnismenge, aber nicht, wie sie berechnet wird, da SQL eine deklarative Programmiersprache ist.

F7. Welche allgemeinen Klauseln werden bei der SELECT-Abfrage in SQL verwendet?

Im Folgenden finden Sie einige häufige SQL-Klauseln, die in Verbindung mit einer SELECT-Abfrage verwendet werden:

WO -Klausel:In SQL wird die WHERE-Klausel verwendet, um Datensätze zu filtern, die abhängig von bestimmten Kriterien erforderlich sind.
BESTELLUNG PER -Klausel:Die ORDER BY-Klausel in SQL wird verwendet, um Daten in aufsteigender (ASC) oder absteigender (DESC) Reihenfolge zu sortieren, abhängig von den angegebenen Feldern (DESC).
GRUPPE NACH -Klausel:Die GROUP BY-Klausel in SQL wird verwendet, um Einträge mit identischen Daten zu gruppieren, und kann mit Aggregationsmethoden verwendet werden, um zusammengefasste Datenbankergebnisse zu erhalten.
HABEN -Klausel in SQL wird zum Filtern von Datensätzen in Kombination mit der GROUP BY-Klausel verwendet. Sie unterscheidet sich von WHERE, da die WHERE-Klausel aggregierte Datensätze nicht filtern kann.

F8. Was sind UNION-, MINUS- und INTERSECT-Befehle?

Der UNION-Operator wird verwendet, um die Ergebnisse zweier Tabellen zu kombinieren und gleichzeitig doppelte Einträge zu entfernen.
Der MINUS-Operator wird verwendet, um Zeilen aus der ersten Abfrage zurückzugeben, aber nicht aus der zweiten Abfrage.
Der INTERSECT-Operator wird verwendet, um die Ergebnisse beider Abfragen in einer einzigen Zeile zu kombinieren.
Bevor Sie eine der oben genannten SQL-Anweisungen ausführen, müssen bestimmte Anforderungen erfüllt sein –
Innerhalb der Klausel muss jede SELECT-Abfrage die gleiche Anzahl an Spalten haben.
Auch die Datentypen in den Spalten müssen vergleichbar sein.
In jeder SELECT-Anweisung müssen die Spalten in der gleichen Reihenfolge sein.

F9. Was ist Cursor? Wie benutzt man einen Cursor?

DECLARE nach jeder Variablendeklaration einen Cursor. Ein SELECT-Statement muss immer mit der Cursor-Definition gekoppelt werden.

Um die Ergebnismenge zu starten, bewegen Sie den Cursor darüber. Bevor Zeilen aus der Ergebnismenge abgerufen werden, muss die OPEN-Anweisung ausgeführt werden.

Verwenden Sie zum Abrufen und Wechseln zur nächsten Zeile in der Ergebnismenge den Befehl FETCH.

Um den Cursor zu deaktivieren, verwenden Sie den Befehl CLOSE.

Verwenden Sie schließlich den Befehl DEALLOCATE, um die Cursordefinition zu entfernen und die damit verbundenen Ressourcen freizugeben.

F10. Listen Sie die verschiedenen Arten von Beziehungen in SQL auf.

Es gibt verschiedene Arten von Beziehungen in der Datenbank:

Eins-zu-Eins – Dies ist eine Verbindung zwischen zwei Tabellen, bei der jeder Datensatz in einer Tabelle maximal einem Datensatz in der anderen entspricht.

Eins-zu-Viele und Viele-zu-Eins – Dies ist die häufigste Verbindung, bei der ein Datensatz in einer Tabelle mit mehreren Datensätzen in einer anderen verknüpft wird.

Many-to-Many – Dies wird verwendet, wenn eine Beziehung definiert wird, die mehrere Instanzen auf jeder Seite erfordert.

Selbstreferenzierende Beziehungen – Wenn eine Tabelle eine Verbindung mit sich selbst deklarieren muss, ist dies die anzuwendende Methode.

F12. Was ist OLTP?

OLTP oder Online-Transaktionsverarbeitung ermöglicht es großen Gruppen von Menschen, große Mengen an Datenbanktransaktionen in Echtzeit auszuführen, normalerweise über das Internet. Eine Datenbanktransaktion findet statt, wenn Daten in einer Datenbank geändert, eingefügt, gelöscht oder abgefragt werden.

F13. Was sind die Unterschiede zwischen OLTP und OLAP?

OLTP steht für Online Transaction Processing, während OLAP für Online Analytical Processing steht. OLTP ist ein Online-Datenbankmodifikationssystem, während OLAP ein Online-Datenbankabfrage-Antwortsystem ist.

F14. Wie erstellt man leere Tabellen mit derselben Struktur wie eine andere Tabelle?

So erstellen Sie leere Tabellen:
Wenn Sie den INTO-Operator verwenden, um die Datensätze einer Tabelle in eine neue Tabelle zu holen, während Sie eine WHERE-Klausel für alle Einträge auf "false" setzen, können Sie leere Tabellen mit derselben Struktur erstellen. Als Ergebnis erstellt SQL eine neue Tabelle mit einer doppelten Struktur, um die abgerufenen Einträge zu akzeptieren, aber es wird nichts in der neuen Tabelle gespeichert, da die WHERE-Klausel aktiv ist.

F15. Was ist PostgreSQL?

1986 erstellte ein Team unter der Leitung von Informatikprofessor Michael Stonebraker PostgreSQL unter dem Namen Postgres. Es wurde entwickelt, um Entwickler bei der Entwicklung von Anwendungen auf Unternehmensebene zu unterstützen, indem Datenintegrität und Fehlertoleranz in Systemen sichergestellt werden. PostgreSQL ist ein vielseitiges, robustes, objektrelationales Open-Source-Datenbankverwaltungssystem auf Unternehmensebene, das variable Workloads und gleichzeitige Benutzer unterstützt. Die internationale Entwicklergemeinschaft hat es ständig unterstützt. PostgreSQL hat aufgrund seiner fehlertoleranten Eigenschaften bei Entwicklern große Anziehungskraft erlangt.
Es ist ein sehr zuverlässiges Datenbankverwaltungssystem, dem mehr als zwei Jahrzehnte Gemeinschaftsarbeit für seine hohe Ausfallsicherheit, Integrität und Genauigkeit zu verdanken sind. Viele Online-, Mobil-, Geodaten- und Analyseanwendungen verwenden PostgreSQL als primären Datenspeicher oder Data Warehouse.

F16. Was sind SQL-Kommentare?

SQL-Kommentare werden verwendet, um Teile von SQL-Anweisungen zu verdeutlichen und zu verhindern, dass SQL-Anweisungen ausgeführt werden. Kommentare sind in vielen Programmiersprachen sehr wichtig. Die Kommentare werden nicht von einer Microsoft Access-Datenbank unterstützt. Daher wird in den Beispielen in Mozilla Firefox und Microsoft Edge die Microsoft Access-Datenbank verwendet.
Einzeilige Kommentare:Beginnt mit zwei aufeinanderfolgenden Bindestrichen (–).
Mehrzeilige Kommentare:Sie beginnen mit /* und enden mit */.

F17. Wozu dient die NVL()-Funktion?

Sie können die NVL-Funktion verwenden, um Nullwerte durch einen Standardwert zu ersetzen. Die Funktion gibt den Wert des zweiten Parameters zurück, wenn der erste Parameter null ist. Wenn der erste Parameter etwas anderes als null ist, wird er allein gelassen.

Diese Funktion wird in Oracle verwendet, nicht in SQL und MySQL. Anstelle der Funktion NVL() hat MySQL die Funktion IFNULL() und SQL Server die Funktion ISNULL().

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.

F18. Funktionen zur Zeichenmanipulation erklären? Erklärt die verschiedenen Typen in SQL.

Ändern, extrahieren und bearbeiten Sie die Zeichenkette mithilfe von Zeichenmanipulationsroutinen. Die Funktion führt ihre Aktion mit den Eingabezeichenfolgen aus und gibt das Ergebnis zurück, wenn ein oder mehrere Zeichen und Wörter eingegeben werden.

Die Zeichenbearbeitungsfunktionen in SQL lauten wie folgt:

A) CONCAT (Verbinden von zwei oder mehr Werten):Diese Funktion wird verwendet, um zwei oder mehr Werte miteinander zu verbinden. Der zweite String wird immer an das Ende des ersten Strings angehängt.

B) SUBSTR:Diese Funktion gibt ein Segment einer Zeichenkette von einem gegebenen Startpunkt zu einem gegebenen Endpunkt zurück.

C) LÄNGE:Diese Funktion gibt die Länge des Strings in numerischer Form inklusive Leerzeichen zurück.

D) INSTR:Diese Funktion berechnet die genaue numerische Position eines Zeichens oder Wortes in einer Zeichenkette.

E) LPAD:Gibt für rechtsbündige Werte die Auffüllung des linken Zeichenwerts zurück.

F) RPAD:Gibt bei einem linksbündigen Wert die Auffüllung des rechten Zeichenwerts zurück.

G) TRIM:Diese Funktion entfernt alle definierten Zeichen vom Anfang, Ende oder beiden Enden einer Zeichenkette. Es reduzierte auch die Menge an verschwendetem Platz.

H) REPLACE:Diese Funktion ersetzt alle Instanzen eines Wortes oder eines Abschnitts einer Zeichenkette (Substring) durch den anderen angegebenen Zeichenkettenwert.

F19. Schreiben Sie die SQL-Abfrage, um das dritthöchste Gehalt eines Mitarbeiters aus einer Tabelle namens „Employees.“ abzurufen

Mitarbeitertabelle

employee_name Gehalt
A 24000
C 34000
D 55000
E 75000
F 21000
G 40000
H 50000

AUSWÄHLEN * AUS (

SELECT Mitarbeitername, Gehalt, DENSE_RANK()

OVER(ORDER BY Salary DESC)r FROM Employee)

WO r=&n;

Um den dritthöchsten Gehaltssatz zu finden, ist n =3

F20. Was ist der Unterschied zwischen den Funktionen RANK() und DENSE_RANK()?

Die Funktion RANK() in der Ergebnismenge definiert den Rang jeder Zeile innerhalb Ihrer geordneten Partition. Wenn beide Reihen den gleichen Rang haben, ist die nächste Zahl in der Rangfolge der vorherige Rang plus eine Anzahl von Duplikaten. Wenn wir zum Beispiel drei Datensätze auf Rang 4 haben, ist die nächste angezeigte Ebene 7.

Die Funktion DENSE_RANK() weist jeder Zeile innerhalb einer Partition basierend auf dem bereitgestellten Spaltenwert ohne Lücken einen eindeutigen Rang zu. Es gibt immer eine Rangfolge in der Rangfolge an. Diese Funktion weist den beiden Zeilen denselben Rang zu, wenn sie denselben Rang haben, wobei der nächste Rang die nächste fortlaufende Nummer ist. Wenn wir zum Beispiel drei Datensätze auf Rang 4 haben, ist die nächste angezeigte Ebene 5.

F21. Was sind Tabellen und Felder?

Eine Tabelle ist eine Sammlung von Datenkomponenten, die in Zeilen und Spalten in einer relationalen Datenbank organisiert sind. Eine Tabelle kann auch als nützliche Darstellung von Beziehungen betrachtet werden. Die einfachste Form der Datenspeicherung ist die Tabelle. Unten sehen Sie ein Beispiel für eine Employee-Tabelle.

ID Name Abteilung Gehalt
1 Rahul Verkäufe 24000
2 Rohini Marketing 34000
3 Schylesh Verkäufe 24000
4 Tarun Analytics 30000

Ein Datensatz oder eine Zeile ist ein einzelner Eintrag in einer Tabelle. In einer Tabelle stellt ein Datensatz eine Sammlung verbundener Daten dar. Die Employee-Tabelle hat beispielsweise vier Datensätze.

Eine Tabelle besteht aus zahlreichen Datensätzen (Zeilen), die jeweils in kleinere Einheiten namens Felder (Spalten) unterteilt werden können. ID, Name, Abteilung und Gehalt sind die vier Felder in der obigen Mitarbeitertabelle.

F22. Was ist eine UNIQUE-Einschränkung?

Die UNIQUE-Einschränkung verhindert, dass identische Werte in einer Spalte in zwei Datensätzen erscheinen. Die UNIQUE-Einschränkung garantiert, dass jeder Wert in einer Spalte eindeutig ist.

F23. Was ist ein Self-Join?

Ein Self-Join ist ein Join-Typ, der verwendet werden kann, um zwei Tabellen zu verbinden. Infolgedessen handelt es sich um eine unäre Beziehung. Jede Zeile der Tabelle ist mit sich selbst und allen anderen Zeilen derselben Tabelle in einem Self-Join verbunden. Daher wird ein Self-Join meistens verwendet, um Zeilen aus derselben Datenbanktabelle zu kombinieren und zu vergleichen.

F24. Was ist die SELECT-Anweisung?

Ein SELECT-Befehl ruft null oder mehr Zeilen aus einer oder mehreren Datenbanktabellen oder -ansichten ab. Der häufigste DML-Befehl (Data Manipulation Language) ist in den meisten Anwendungen SELECT. SELECT-Abfragen definieren eine Ergebnismenge, aber nicht, wie sie berechnet wird, da SQL eine deklarative Programmiersprache ist.

F25. Welche allgemeinen Klauseln werden bei der SELECT-Abfrage in SQL verwendet?

Im Folgenden finden Sie einige häufige SQL-Klauseln, die in Verbindung mit einer SELECT-Abfrage verwendet werden:

WHERE-Klausel:In SQL wird die WHERE-Klausel verwendet, um Datensätze zu filtern, die in Abhängigkeit von bestimmten Kriterien erforderlich sind.
ORDER BY-Klausel:Die ORDER BY-Klausel in SQL wird verwendet, um Daten in aufsteigender (ASC) oder absteigender (DESC) Reihenfolge zu sortieren, abhängig von den angegebenen Feldern (DESC).
GROUP BY-Klausel:Die GROUP BY-Klausel in SQL wird zum Gruppieren von Einträgen mit identischen Daten verwendet und kann mit Aggregationsmethoden verwendet werden, um zusammengefasste Datenbankergebnisse zu erhalten.
Die HAVING-Klausel in SQL wird zum Filtern von Datensätzen in Kombination mit der GROUP BY-Klausel verwendet. Sie unterscheidet sich von WHERE, da die WHERE-Klausel aggregierte Datensätze nicht filtern kann.

F26. Was sind UNION-, MINUS- und INTERSECT-Befehle?

Der UNION-Operator wird verwendet, um die Ergebnisse zweier Tabellen zu kombinieren und gleichzeitig doppelte Einträge zu entfernen.

Der MINUS-Operator wird verwendet, um Zeilen aus der ersten Abfrage zurückzugeben, aber nicht aus der zweiten Abfrage.

Der INTERSECT-Operator wird verwendet, um die Ergebnisse beider Abfragen in einer einzigen Zeile zu kombinieren.
Vor dem Ausführen einer der oben genannten SQL-Anweisungen müssen bestimmte Voraussetzungen erfüllt sein –

Innerhalb der Klausel muss jede SELECT-Abfrage die gleiche Anzahl an Spalten haben.

Auch die Datentypen in den Spalten müssen vergleichbar sein.

In jeder SELECT-Anweisung müssen die Spalten in der gleichen Reihenfolge sein.

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.

F27. Was ist Cursor? Wie benutzt man einen Cursor?

DECLARE nach jeder Variablendeklaration einen Cursor. Ein SELECT-Statement muss immer mit der Cursor-Definition gekoppelt werden.

Um die Ergebnismenge zu starten, bewegen Sie den Cursor darüber. Bevor Zeilen aus der Ergebnismenge abgerufen werden, muss die OPEN-Anweisung ausgeführt werden.

Verwenden Sie zum Abrufen und Wechseln zur nächsten Zeile in der Ergebnismenge den Befehl FETCH.

Um den Cursor zu deaktivieren, verwenden Sie den Befehl CLOSE.

Verwenden Sie schließlich den Befehl DEALLOCATE, um die Cursordefinition zu entfernen und die damit verbundenen Ressourcen freizugeben.

F28. Listen Sie die verschiedenen Arten von Beziehungen in SQL auf.

Es gibt verschiedene Arten von Beziehungen in der Datenbank:
One-to-One – Dies ist eine Verbindung zwischen zwei Tabellen, bei der jeder Datensatz in einer Tabelle maximal einem Datensatz in der anderen entspricht.
One-to-Many und Many-to-One – Dies ist die häufigste Verbindung, bei der ein Datensatz in einer Tabelle mit mehreren Datensätzen in einer anderen verknüpft wird.
Many-to-Many – Dies wird verwendet, wenn eine Beziehung definiert wird, die mehrere Instanzen auf jeder Seite erfordert.
Selbstreferenzierende Beziehungen – Wenn eine Tabelle eine Verbindung mit sich selbst deklarieren muss, ist dies die anzuwendende Methode.

F29. Was ist ein SQL-Beispiel?

SQL ist eine Datenbankabfragesprache, mit der Sie Daten aus Datenbanken bearbeiten, entfernen und anfordern können. Die folgenden Anweisungen sind einige Beispiele für SQL-Anweisungen:

  • AUSWÄHLEN
  • EINFÜGEN
  • AKTUALISIEREN
  • LÖSCHEN
  • DATENBANK ERSTELLEN
  • DATENBANK ÄNDERN

F30. Was sind grundlegende SQL-Kenntnisse?

SQL-Kenntnisse unterstützen Datenanalysten bei der Erstellung, Pflege und dem Abruf von Daten aus relationalen Datenbanken, die Daten in Spalten und Zeilen unterteilen. Es ermöglicht Benutzern auch, Daten effizient abzurufen, zu aktualisieren, zu manipulieren, einzufügen und zu ändern.

Die grundlegendsten Fähigkeiten, die ein SQL-Experte besitzen sollte, sind:

  1. Datenbankverwaltung
  2. Strukturieren einer Datenbank
  3. SQL-Klauseln und -Anweisungen erstellen
  4. SQL-Systemkenntnisse wie MYSQL, PostgreSQL
  5. PHP-Expertise ist hilfreich.
  6. SQL-Daten analysieren
  7. Verwenden von WAMP mit SQL zum Erstellen einer Datenbank
  8. OLAP-Kenntnisse

F31. Was ist ein Schema in SQL Server?

Ein Schema ist eine visuelle Darstellung der Datenbank, die logisch ist. Es baut die Beziehungen zwischen den zahlreichen Entitäten der Datenbank auf und spezifiziert sie. Es bezieht sich auf die verschiedenen Arten von Einschränkungen, die auf eine Datenbank angewendet werden können. Es beschreibt auch die verschiedenen Datenarten. Es kann auch für Tabellen und Ansichten verwendet werden.

Schemata gibt es in einer Vielzahl von Formen und Größen. Star-Schema und Snowflake-Schema sind zwei der beliebtesten. Die Entitäten in einem Sternschema werden in Sternform dargestellt, während die in einem Schneeflockenschema in Schneeflockenform angezeigt werden.
Jede Datenbankarchitektur basiert auf Schemata.


F32. Wie erstelle ich eine temporäre Tabelle in SQL Server?

Temporäre Tabellen werden in TempDB erstellt und nach dem Schließen der letzten Verbindung automatisch gelöscht. Wir können temporäre Tabellen verwenden, um Zwischenergebnisse zu speichern und zu verarbeiten. Wenn wir temporäre Daten speichern müssen, sind temporäre Tabellen praktisch.

Das Folgende ist die Syntax zum Erstellen einer temporären Tabelle:

CREATE TABLE #Employee (ID INT, Name VARCHAR(25))
INSERT INTO #Employee VALUES (01, „Ashish“), (02, „Atul“)

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.


F33. Wie installiere ich SQL Server in Windows 11?

Installieren Sie SQL Server Management Studio unter Windows 11

Schritt 1: Klicken Sie auf SSMS, wodurch Sie zur Seite von SQL Server Management Studio gelangen.

Schritt 2: Klicken Sie außerdem auf den Link SQL Server Management Studio und tippen Sie auf Datei speichern.

Schritt 3: Speichern Sie diese Datei auf Ihrem lokalen Laufwerk und wechseln Sie in den Ordner.

Schritt 4: Das Setup-Fenster wird angezeigt, und hier können Sie den Ort auswählen, an dem Sie die Datei speichern möchten.
Schritt 5: Klicken Sie auf Installieren.
Schritt 6: Schließen Sie das Fenster nach Abschluss der Installation.
Schritt 7: Gehen Sie außerdem zurück zu Ihrem Startmenü und suchen Sie nach SQL Server Management Studio.

Schritt 8: Doppelklicken Sie außerdem darauf, und die Anmeldeseite wird angezeigt, sobald sie angezeigt wird.

Schritt 9: Sie sollten Ihren Servernamen sehen können. Wenn dies jedoch nicht sichtbar ist, klicken Sie auf den Dropdown-Pfeil auf dem Server und tippen Sie auf Durchsuchen.

Schritt 10: Wählen Sie Ihren SQL-Server aus und klicken Sie auf Verbinden.

Danach verbindet sich der SQL-Server und Windows 11 läuft einwandfrei.

F34. Was ist wann in SQL Server der Fall?

Die CASE-Anweisung wird verwendet, um eine Logik zu konstruieren, in der der Wert einer Spalte durch die Werte anderer Spalten bestimmt wird.

Mindestens ein Satz von WHEN- und THEN-Befehlen bildet die CASE-Anweisung von SQL Server. Die zu prüfende Bedingung wird durch die WHEN-Anweisung spezifiziert. Wenn die WENN-Bedingung WAHR zurückgibt, erklärt der DANN-Satz, was zu tun ist.

Wenn keine der WHEN-Bedingungen wahr zurückgibt, wird die ELSE-Anweisung ausgeführt. Das Schlüsselwort END beendet die CASE-Anweisung.

CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;

F35. NoSQL vs. SQL

Zusammenfassend sind die folgenden fünf Hauptunterschiede zwischen SQL und NoSQL:

Relationale Datenbanken sind SQL, während nicht-relationale Datenbanken NoSQL sind.

SQL-Datenbanken haben ein bestimmtes Schema und verwenden eine strukturierte Abfragesprache. Für unstrukturierte Daten verwenden NoSQL-Datenbanken dynamische Schemas.

SQL-Datenbanken werden vertikal skaliert, aber NoSQL-Datenbanken werden horizontal skaliert.

NoSQL-Datenbanken sind Dokument-, Schlüsselwert-, Diagramm- oder Wide-Column-Speicher, während SQL-Datenbanken tabellenbasiert sind.

SQL-Datenbanken zeichnen sich durch mehrzeilige Transaktionen aus, während NoSQL sich durch unstrukturierte Daten wie Dokumente und JSON auszeichnet.

F36. Was ist der Unterschied zwischen NOW() und CURRENT_DATE()?
NOW() gibt eine konstante Zeit zurück, die den Zeitpunkt angibt, zu dem die Ausführung der Anweisung begonnen hat. (Innerhalb einer gespeicherten Funktion oder eines Triggers gibt NOW() die Zeit zurück, zu der die Ausführung der Funktion oder der auslösenden Anweisung begonnen hat.
Der einfache Unterschied zwischen NOW() und CURRENT_DATE() besteht darin, dass NOW() das aktuelle Datum und die aktuelle Uhrzeit im Format „JJJJ-MM_TT HH:MM:SS“ abruft, während CURRENT_DATE() das Datum des aktuellen Tages „JJJJ“ abruft -MM_TT'.

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.

F37. Was sind BLOB und TEXT in MySQL?

BLOB steht für Binary Huge Objects und kann zum Speichern von Binärdaten verwendet werden, während TEXT zum Speichern einer großen Anzahl von Zeichenfolgen verwendet werden kann. BLOB kann zum Speichern von Binärdaten verwendet werden, darunter Bilder, Filme, Audio und Anwendungen.
BLOB-Werte funktionieren ähnlich wie Byte-Strings, und ihnen fehlt ein Zeichensatz. Infolgedessen sind die numerischen Werte von Bytes vollständig vom Vergleich und Sortieren abhängig.
TEXT-Werte verhalten sich ähnlich wie eine Zeichenfolge oder eine nicht-binäre Zeichenfolge. Der Vergleich/Sortierung von TEXT ist vollständig abhängig von der Zeichensatzsammlung.

F38. Wie entferne ich doppelte Zeilen in SQL?

Wenn die SQL-Tabelle doppelte Zeilen enthält, müssen die doppelten Zeilen entfernt werden.

Nehmen wir die folgende Tabelle als unseren Datensatz an:

ID Name Alter
1 A 21
2 B 23
2 B 23
4 D 22
5 E 25
6 G 26
5 E 25

Die folgende SQL-Abfrage entfernt die doppelten IDs aus der Tabelle:

DELETE FROM Tabelle WHERE ID IN (
AUSWÄHLEN
ID, ANZAHL(ID)
AUS-Tabelle
GRUPPE NACH ID
HABEN
ANZAHL (ID)> 1);

F39. Wie erstelle ich eine gespeicherte Prozedur mit SQL Server?

Eine gespeicherte Prozedur ist ein Stück vorbereiteten SQL-Codes, den Sie speichern und immer wieder verwenden können.
Wenn Sie also häufig eine SQL-Abfrage erstellen, speichern Sie sie als gespeicherte Prozedur und rufen Sie sie dann auf, um sie auszuführen.
Sie können einer gespeicherten Prozedur auch Parameter zuführen, damit sie basierend auf den Werten der angegebenen Parameter handeln kann.

Syntax gespeicherter Prozeduren

CREATE PROCEDURE Prozedurname

AS

sql_statement

GEHEN;

Ausführen einer gespeicherten Prozedur

EXEC Prozedurname;


Q40. Was ist Datenbank-Blackbox-Testing?

Black Box Testing ist ein Softwaretestansatz, bei dem die Funktionen von Softwareanwendungen getestet werden, ohne die interne Codestruktur, Implementierungsdetails oder interne Routen zu kennen. Black Box Testing ist eine Art Softwaretest, der sich auf die Ein- und Ausgabe von Softwareanwendungen konzentriert und vollständig von Softwareanforderungen und -spezifikationen bestimmt wird. Verhaltenstests ist ein anderer Name dafür.


F41. Was sind die verschiedenen Arten von SQL-Sandboxen?

SQL Sandbox ist eine sichere Umgebung innerhalb von SQL Server, in der nicht vertrauenswürdige Programme ausgeführt werden können. Es gibt drei verschiedene Arten von SQL-Sandboxen:

Safe Access Sandbox:In dieser Umgebung kann ein Benutzer SQL-Aktivitäten wie das Erstellen gespeicherter Prozeduren, Trigger usw. ausführen, aber er kann nicht auf den Speicher zugreifen oder Dateien erstellen.

Sandbox für externen Zugriff:Benutzer können auf Dateien zugreifen, ohne die Speicherzuweisung ändern zu können.

Sandbox für unsicheren Zugriff:Diese enthält nicht vertrauenswürdigen Code, der einem Benutzer den Zugriff auf Speicher ermöglicht.

Kommen wir zur nächsten Frage in diesen SQL-Interviewfragen.

F42. Wo wird die MyISAM-Tabelle gespeichert?

Vor der Einführung von MySQL 5.5 im Dezember 2009 war MyISAM die Standardspeicher-Engine für relationale MySQL-Datenbankverwaltungssystemversionen. Es basiert auf dem älteren ISAM-Code, bietet aber viele zusätzliche Funktionen. Jede MyISAM-Tabelle wird auf der Platte in drei Dateien aufgeteilt (wenn sie nicht partitioniert ist). Die Dateinamen beginnen mit dem Tabellennamen und enden mit einer Erweiterung, die den Dateityp angibt. Die Tabellendefinition wird in einer.frm-Datei gespeichert, diese Datei ist jedoch nicht Teil der MyISAM-Engine; Stattdessen ist es Teil des Servers. Das Suffix der Datendatei ist.MYD (MYData). Die Erweiterung der Indexdatei ist.MYI (MYIndex). Wenn Sie Ihre Indexdatei verlieren, können Sie sie jederzeit wiederherstellen, indem Sie Indizes neu erstellen.

F43. Wie findet man das n-thöchste Gehalt in SQL?
Die typischste Interviewfrage besteht darin, das N-höchste Gehalt in einer Tabelle zu finden. Diese Arbeit kann mit der Funktion dense rank() durchgeführt werden.
Mitarbeitertabelle

employee_name Gehalt
A 24000
C 34000
D 55000
E 75000
F 21000
G 40000
H 50000

AUSWÄHLEN * AUS (

SELECT Mitarbeitername, Gehalt, DENSE_RANK()

OVER(ORDER BY Salary DESC)r FROM Employee)

WO r=&n;

Um den zweithöchsten Gehaltssatz zu finden, gilt n =2

Um das dritthöchste Gehalt zu finden, ist n =3 und so weiter.

F44. Was meinst du mit Tabelle und Feld in SQL?

Eine Tabelle bezieht sich auf eine organisierte Sammlung von Daten in Form von Zeilen und Spalten. Ein Feld bezieht sich auf die Anzahl der Spalten in einer Tabelle. Zum Beispiel:

Tabelle :Schüler Informationen
Feld :Stu-ID, Stu-Name, Stu-Marken

F45. Was sind Joins in SQL?

Eine JOIN-Klausel wird verwendet, um Zeilen aus zwei oder mehr Tabellen zu kombinieren, basierend auf einer verwandten Spalte zwischen ihnen. Es wird verwendet, um zwei Tabellen zusammenzuführen oder Daten von dort abzurufen. Es gibt 4 Arten von Joins, wie Sie unten sehen können:

  • Inner join: Inner Join in SQL is the most common type of join. It is used to return all the rows from multiple tables where the join condition is satisfied.
  • Left Join: Left Join in SQL is used to return all the rows from the left table but only the matching rows from the right table where the join condition is fulfilled.

  • Right Join: Right Join in SQL is used to return all the rows from the right table but only the matching rows from the left table where the join condition is fulfilled.

  • Full Join: Full join returns all the records when there is a match in any of the tables. Therefore, it returns all the rows from the left-hand side table and all the rows from the right-hand side table.

Let’s move to the next question in this SQL Interview Questions.

Q46. What is the difference between CHAR and VARCHAR2 datatype in SQL?

Both Char and Varchar2 are used for characters datatype but varchar2 is used for character strings of variable length whereas Char is used for strings of fixed length. For example, char(10) can only store 10 characters and will not be able to store a string of any other length whereas varchar2(10) can store any length i.e 6,8,2 in this variable.

Q47. What is a Primary key?

  • A Primary key in SQL is a column (or collection of columns) or a set of columns that uniquely identifies each row in the table.
  • Uniquely identifies a single row in the table
  • Null values not allowed

Example- In the Student table, Stu_ID is the primary key.

Q48. What are Constraints?

Constraints in SQL are used to specify the limit on the data type of the table. It can be specified while creating or altering the table statement. The sample of constraints are:

  • NOT NULL
  • CHECK
  • DEFAULT
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY

Q49. What is the difference between DELETE and TRUNCATE statements?

DELETE vs TRUNCATE

DELETE TRUNCATE
Delete command is used to delete a row in a table. Truncate is used to delete all the rows from a table.
You can rollback data after using delete statement. You cannot rollback data.
It is a DML command. It is a DDL command.
It is slower than truncate statement. It is faster.

Q50. What is a Unique key?

  • Uniquely identifies a single row in the table.
  • Multiple values allowed per table.
  • Null values allowed.

Apart from this SQL Interview Questions blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q51. What is a Foreign key in SQL?

  • Foreign key maintains referential integrity by enforcing a link between the data in two tables.
  • The foreign key in the child table references the primary key in the parent table.
  • The foreign key constraint prevents actions that would destroy links between the child and parent tables.

Q52. What do you mean by data integrity?

Data Integrity defines the accuracy as well as the consistency of the data stored in a database. It also defines integrity constraints to enforce business rules on the data when it is entered into an application or a database.

Q53. What is the difference between clustered and non-clustered index in SQL?

The differences between the clustered and non clustered index in SQL are :

  1. Clustered index is used for easy retrieval of data from the database and its faster whereas reading from non clustered index is relatively slower.
  2. Clustered index alters the way records are stored in a database as it sorts out rows by the column which is set to be clustered index whereas in a non clustered index, it does not alter the way it was stored but it creates a separate object within a table which points back to the original table rows after searching.
  3. One table can only have one clustered index whereas it can have many non clustered index.

Q54. Write a SQL query to display the current date?

In SQL, there is a built-in function called GetDate() which helps to return the current timestamp/date.

Q55. What do you understand by query optimization?

The phase that identifies a plan for evaluation query which has the least estimated cost is known as query optimization.

The advantages of query optimization are as follows:

  • The output is provided faster
  • A larger number of queries can be executed in less time
  • Reduces time and space complexity

Q56. What do you mean by Denormalization?

Denormalization refers to a technique which is used to access data from higher to lower forms of a database. It helps the database managers to increase the performance of the entire infrastructure as it introduces redundancy into a table. It adds the redundant data into a table by incorporating database queries that combine data from various tables into a single table.

Q57. What are Entities and Relationships?

Entities :A person, place, or thing in the real world about which data can be stored in a database. Tables store data that represents one type of entity. For example – A bank database has a customer table to store customer information. The customer table stores this information as a set of attributes (columns within the table) for each customer.

Relationships :Relation or links between entities that have something to do with each other. For example – The customer name is related to the customer account number and contact information, which might be in the same table. There can also be relationships between separate tables (for example, customer to accounts).

Let’s move to the next question in this SQL Interview Questions.


Q58. What is an Index?

An index refers to a performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and hence it will be faster to retrieve data.

Q59 . Explain different types of index in SQL.

There are three types of index in SQL namely:

Unique Index:

This index does not allow the field to have duplicate values if the column is unique indexed. If a primary key is defined, a unique index can be applied automatically.

Clustered Index:

This index reorders the physical order of the table and searches based on the basis of key values. Each table can only have one clustered index.

Non-Clustered Index:

Non-Clustered Index does not alter the physical order of the table and maintains a logical order of the data. Each table can have many nonclustered indexes.

Q60. What is Normalization and what are the advantages of it?

Normalization in SQL is the process of organizing data to avoid duplication and redundancy. Some of the advantages are:

  • Better Database organization
  • More Tables with smaller rows
  • Efficient data access
  • Greater Flexibility for Queries
  • Quickly find the information
  • Easier to implement Security
  • Allows easy modification
  • Reduction of redundant and duplicate data
  • More Compact Database
  • Ensure Consistent data after modification

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q61. What is the difference between DROP and TRUNCATE commands?

DROP command removes a table and it cannot be rolled back from the database whereas TRUNCATE command removes all the rows from the table.

Q62. Explain different types of Normalization.

There are many successive levels of normalization. These are called normal forms . Each consecutive normal form depends on the previous one.The first three normal forms are usually adequate.

Normal Forms are used in database tables to remove or decrease duplication. The following are the many forms:

First Normal Form:
When every attribute in a relation is a single-valued attribute, it is said to be in first normal form. The first normal form is broken when a relation has a composite or multi-valued property.

Second Normal Form:

A relation is in second normal form if it meets the first normal form’s requirements and does not contain any partial dependencies. In 2NF, a relation has no partial dependence, which means it has no non-prime attribute that is dependent on any suitable subset of any table candidate key. Often, the problem may be solved by setting a single column Primary Key.

Third Normal Form:
If a relation meets the requirements for the second normal form and there is no transitive dependency, it is said to be in the third normal form.

Q63. What is OLTP?

OLTP, or online transactional processing, allows huge groups of people to execute massive amounts of database transactions in real time, usually via the internet. A database transaction occurs when data in a database is changed, inserted, deleted, or queried.

What are the differences between OLTP and OLAP?

OLTP stands for online transaction processing, whereas OLAP stands for online analytical processing. OLTP is an online database modification system, whereas OLAP is an online database query response system.

Q64. How to create empty tables with the same structure as another table?

To create empty tables:

Using the INTO operator to fetch the records of one table into a new table while setting a WHERE clause to false for all entries, it is possible to create empty tables with the same structure. As a result, SQL creates a new table with a duplicate structure to accept the fetched entries, but nothing is stored into the new table since the WHERE clause is active.

Q65. What is PostgreSQL?

In 1986, a team lead by Computer Science Professor Michael Stonebraker created PostgreSQL under the name Postgres. It was created to aid developers in the development of enterprise-level applications by ensuring data integrity and fault tolerance in systems. PostgreSQL is an enterprise-level, versatile, resilient, open-source, object-relational database management system that supports variable workloads and concurrent users. The international developer community has constantly backed it. PostgreSQL has achieved significant appeal among developers because to its fault-tolerant characteristics.
It’s a very reliable database management system, with more than two decades of community work to thank for its high levels of resiliency, integrity, and accuracy. Many online, mobile, geospatial, and analytics applications utilise PostgreSQL as their primary data storage or data warehouse.

Q66. What are SQL comments?

SQL Comments are used to clarify portions of SQL statements and to prevent SQL statements from being executed. Comments are quite important in many programming languages. The comments are not supported by a Microsoft Access database. As a result, the Microsoft Access database is used in the examples in Mozilla Firefox and Microsoft Edge.
Single Line Comments:It starts with two consecutive hyphens (–).
Multi-line Comments:It starts with /* and ends with */.

Let’s move to the next question in this SQL Interview Questions.

Q67. What is the difference between the RANK() and DENSE_RANK() functions?

The RANK() function in the result set defines the rank of each row within your ordered partition. If both rows have the same rank, the next number in the ranking will be the previous rank plus a number of duplicates. If we have three records at rank 4, for example, the next level indicated is 7.

The DENSE_RANK() function assigns a distinct rank to each row within a partition based on the provided column value, with no gaps. It always indicates a ranking in order of precedence. This function will assign the same rank to the two rows if they have the same rank, with the next rank being the next consecutive number. If we have three records at rank 4, for example, the next level indicated is 5.

Q68. What is SQL Injection?

SQL injection is a sort of flaw in website and web app code that allows attackers to take control of back-end processes and access, retrieve, and delete sensitive data stored in databases. In this approach, malicious SQL statements are entered into a database entry field, and the database becomes exposed to an attacker once they are executed. By utilising data-driven apps, this strategy is widely utilised to get access to sensitive data and execute administrative tasks on databases. SQLi attack is another name for it.

The following are some examples of SQL injection:

  • Getting access to secret data in order to change a SQL query to acquire the desired results.
  • UNION attacks are designed to steal data from several database tables.
  • Examine the database to get information about the database’s version and structure

Q69. How many Aggregate functions are available in SQL?

SQL aggregate functions provide information about a database’s data. AVG, for example, returns the average of a database column’s values.

SQL provides seven (7) aggregate functions, which are given below:

AVG():returns the average value from specified columns.
COUNT():returns the number of table rows, including rows with null values.
MAX():returns the largest value among the group.
MIN():returns the smallest value among the group.
SUM():returns the total summed values(non-null) of the specified column.
FIRST():returns the first value of an expression.
LAST():returns the last value of an expression.

Q70. What is the default ordering of data using the ORDER BY clause? How could it be changed?

The ORDER BY clause in MySQL can be used without the ASC or DESC modifiers. The sort order is preset to ASC or ascending order when this attribute is absent from the ORDER BY clause.

Q71. How do we use the DISTINCT statement? What is its use?

The SQL DISTINCT keyword is combined with the SELECT query to remove all duplicate records and return only unique records. There may be times when a table has several duplicate records.
The DISTINCT clause in SQL is used to eliminate duplicates from a SELECT statement’s result set.

Q72. What are the syntax and use of the COALESCE function?

From a succession of expressions, the COALESCE function returns the first non-NULL value. The expressions are evaluated in the order that they are supplied, and the function’s result is the first non-null value. Only if all of the inputs are null does the COALESCE method return NULL.

The syntax of COALESCE function is COALESCE (exp1, exp2, …. expn)

Q73. What is the ACID property in a database?

ACID stands for Atomicity, Consistency, Isolation, Durability. It is used to ensure that the data transactions are processed reliably in a database system.

  • Atomicity: Atomicity refers to the transactions that are completely done or failed where transaction refers to a single logical operation of a data. Das bedeutet, wenn ein Teil einer Transaktion fehlschlägt, schlägt die gesamte Transaktion fehl und der Datenbankstatus bleibt unverändert.
  • Consistency: Consistency ensures that the data must meet all the validation rules. Mit einfachen Worten können Sie sagen, dass Ihre Transaktion die Datenbank niemals verlässt, ohne ihren Status zu vervollständigen.
  • Isolation: The main goal of isolation is concurrency control.
  • Durability: Durability means that if a transaction has been committed, it will occur whatever may come in between such as power loss, crash or any sort of error.
Want to upskill yourself to get ahead in your career? Check out this video in this SQL Interview Questions

Top 10 Technologies to Learn in 2022 | Edureka

Q74. What do you mean by “Trigger” in SQL?

Trigger in SQL is are a special type of stored procedures that are defined to execute automatically in place or after data modifications. It allows you to execute a batch of code when an insert, update or any other query is executed against a specific table.

Q75. What are the different operators available in SQL?

There are three operators available in SQL, namely:

  1. Arithmetic Operators
  2. Logical Operators
  3. Comparison Operators

Apart from this SQL Interview Questions blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q76. Are NULL values same as that of zero or a blank space?

A NULL value is not at all same as that of zero or a blank space. NULL value represents a value which is unavailable, unknown, assigned or not applicable whereas a zero is a number and blank space is a character.

Q77. What is the difference between cross join and natural join?

The cross join produces the cross product or Cartesian product of two tables whereas the natural join is based on all the columns having the same name and data types in both the tables.

Q78. What is subquery in SQL?

A subquery is a query inside another query where a query is defined to retrieve data or information back from the database. In a subquery, the outer query is called as the main query whereas the inner query is called subquery. Subqueries are always executed first and the result of the subquery is passed on to the main query. It can be nested inside a SELECT, UPDATE or any other query. A subquery can also use any comparison operators such as>,

Q79. What are the different types of a subquery?

There are two types of subquery namely, Correlated and Non-Correlated.

Correlated subquery :These are queries which select the data from a table referenced in the outer query. It is not considered as an independent query as it refers to another table and refers the column in a table.

Non-Correlated subquery :This query is an independent query where the output of subquery is substituted in the main query.

Let’s move to the next question in this SQL Interview Questions.

Q80. List the ways to get the count of records in a table?

To count the number of records in a table in SQL, you can use the below commands:

SELECT * FROM table1

SELECT COUNT(*) FROM table1

SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q81. Write a SQL query to find the names of employees that begin with ‘A’?

To display name of the employees that begin with ‘A’, type in the below command:

SELECT * FROM Table_name WHERE EmpName like 'A%'

Q82. Write a SQL query to get the third-highest salary of an employee from employee_table?

SELECT TOP 1 salary
FROM(
SELECT TOP 3 salary
FROM employee_table
ORDER BY salary DESC) AS emp
ORDER BY salary ASC;

Q83. What is the need for group functions in SQL?

Group functions work on the set of rows and return one result per group. Some of the commonly used group functions are:AVG, COUNT, MAX, MIN, SUM, VARIANCE.

Q84. What is a Relationship and what are they?

Relation or links are between entities that have something to do with each other. Relationships are defined as the connection between the tables in a database. There are various relationships, namely:

  • One to One Relationship.
  • One to Many Relationship.
  • Many to One Relationship.
  • Self-Referencing Relationship.

Q85. How can you insert NULL values in a column while inserting the data?

NULL values in SQL can be inserted in the following ways:

  • Implicitly by omitting column from column list.
  • Explicitly by specifying NULL keyword in the VALUES clause

Q86. What is the main difference between ‘BETWEEN’ and ‘IN’ condition operators?

BETWEEN operator is used to display rows based on a range of values in a row whereas the IN condition operator is used to check for values contained in a specific set of values.

Example of BETWEEN:

SELECT * FROM Students where ROLL_NO BETWEEN 10 AND 50;
Example of IN:
SELECT * FROM students where ROLL_NO IN (8,15,25);

Q87. Why are SQL functions used?

SQL functions are used for the following purposes:

  • To perform some calculations on the data
  • To modify individual data items
  • To manipulate the output
  • To format dates and numbers
  • To convert the data types

Q88. What is the need for MERGE statement?

This statement allows conditional update or insertion of data into a table. It performs an UPDATE if a row exists, or an INSERT if the row does not exist.

Q89. What do you mean by recursive stored procedure?

Recursive stored procedure refers to a stored procedure which calls by itself until it reaches some boundary condition. This recursive function or procedure helps the programmers to use the same set of code n number of times.

Q90. What is CLAUSE in SQL?

SQL clause helps to limit the result set by providing a condition to the query. A clause helps to filter the rows from the entire set of records.

For example – WHERE, HAVING clause.

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for a structured training from edureka! Click below to know more.

Q91. What is the difference between ‘HAVING’ CLAUSE and a ‘WHERE’ CLAUSE?

HAVING clause can be used only with SELECT statement. It is usually used in a GROUP BY clause and whenever GROUP BY is not used, HAVING behaves like a WHERE clause.
Having Clause is only used with the GROUP BY function in a query whereas WHERE Clause is applied to each row before they are a part of the GROUP BY function in a query.

Q92. List the ways in which Dynamic SQL can be executed?

Following are the ways in which dynamic SQL can be executed:

  • Write a query with parameters.
  • Using EXEC.
  • Using sp_executesql.

Q93. What are the various levels of constraints?

Constraints are the representation of a column to enforce data entity and consistency. There are two levels of a constraint, namely:

  • column level constraint
  • table level constraint

Q94. How can you fetch common records from two tables?

You can fetch common records from two tables using INTERSECT. For example:


Select studentID from student. INTERSECT Select StudentID from Exam

Q95. List some case manipulation functions in SQL?

There are three case manipulation functions in SQL, namely:

  • LOWER:This function returns the string in lowercase. It takes a string as an argument and returns it by converting it into lower case. Syntax:
 LOWER(‘string’)
  • UPPER:This function returns the string in uppercase. It takes a string as an argument and returns it by converting it into uppercase. Syntax:
UPPER(‘string’)
  • INITCAP:This function returns the string with the first letter in uppercase and rest of the letters in lowercase. Syntax:
 INITCAP(‘string’)

Apart from this SQL Interview Questions blog, if you want to get trained from professionals on this technology, you can opt for a structured training from edureka! Click below to know more.

Q96. What are the different set operators available in SQL?

Some of the available set operators are – Union, Intersect or Minus operators.

Q97. What is an ALIAS command?

ALIAS command in SQL is the name that can be given to any table or a column. This alias name can be referred in WHERE clause to identify a particular table or a column.

For example-

Select emp.empID, dept.Result from employee emp, department as dept where emp.empID=dept.empID

In the above example, emp refers to alias name for employee table and dept refers to alias name for department table.

Let’s move to the next question in this SQL Interview Questions.

Q98. What are aggregate and scalar functions?

Aggregate functions are used to evaluate mathematical calculation and returns a single value. These calculations are done from the columns in a table. For example- max(),count() are calculated with respect to numeric.

Scalar functions return a single value based on the input value. For example – UCASE(), NOW() are calculated with respect to string.

Let’s move to the next question in this SQL Interview Questions.

Q99. How can you fetch alternate records from a table?

You can fetch alternate records i.e both odd and even row numbers. For example- To display even numbers, use the following command:

Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0

Now, to display odd numbers:

Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1

Q100. Name the operator which is used in the query for pattern matching?

LIKE operator is used for pattern matching, and it can be used as -.

  1. % – It matches zero or more characters.

For example- select * from students where studentname like ‘a%’

_ (Underscore) – it matches exactly one character.
For example- select * from student where studentname like ‘abc_’

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q101. How can you select unique records from a table?

You can select unique records from a table by using the DISTINCT keyword.

Select DISTINCT studentID from Student

Using this command, it will print unique student id from the table Student.

Q102. How can you fetch first 5 characters of the string?

There are a lot of ways to fetch characters from a string. For example:

Select SUBSTRING(StudentName,1,5) as studentname from student

Q103 . What is the main difference between SQL and PL/SQL?

SQL is a query language that allows you to issue a single query or execute a single insert/update/delete whereas PL/SQL is Oracle’s “Procedural Language” SQL, which allows you to write a full program (loops, variables, etc.) to accomplish multiple operations such as selects/inserts/updates/deletes.

Q104. What is a View?

A view is a virtual table which consists of a subset of data contained in a table. Since views are not present, it takes less space to store. View can have data of one or more tables combined and it depends on the relationship.

Let’s move to the next question in this SQL Interview Questions.

Q105. What are Views used for?

A view refers to a logical snapshot based on a table or another view. It is used for the following reasons:

  • Restricting access to data.
  • Making complex queries simple.
  • Ensuring data independence.
  • Providing different views of same data.

Q106. What is a Stored Procedure?

A Stored Procedure is a function which consists of many SQL statements to access the database system. Several SQL statements are consolidated into a stored procedure and execute them whenever and wherever required which saves time and avoid writing code again and again.

Q107. List some advantages and disadvantages of Stored Procedure?

Advantages :

A Stored Procedure can be used as a modular programming which means create once, store and call for several times whenever it is required. This supports faster execution. It also reduces network traffic and provides better security to the data.

Disadvantage :

The only disadvantage of Stored Procedure is that it can be executed only in the database and utilizes more memory in the database server.

Q108. List all the types of user-defined functions?

There are three types of user-defined functions, namely:

  • Scalar Functions
  • Inline Table-valued functions
  • Multi-statement valued functions

Scalar returns the unit, variant defined the return clause. Other two types of defined functions return table.

Let’s move to the next question in this SQL Interview Questions.

Q109. What do you mean by Collation?

Collation is defined as a set of rules that determine how data can be sorted as well as compared. Character data is sorted using the rules that define the correct character sequence along with options for specifying case-sensitivity, character width etc.

Let’s move to the next question in this SQL Interview Questions.

Q110. What are the different types of Collation Sensitivity?

Following are the different types of collation sensitivity:

  • Case Sensitivity:A and a and B and b.
  • Kana Sensitivity:Japanese Kana characters.
  • Width Sensitivity:Single byte character and double-byte character.
  • Accent Sensitivity.

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for structured training from edureka!

Q111. What are Local and Global variables?

Local variables:

These variables can be used or exist only inside the function. These variables are not used or referred by any other function.

Global variables:

These variables are the variables which can be accessed throughout the program. Global variables cannot be created whenever that function is called.

Q112. What is Auto Increment in SQL?

Autoincrement keyword allows the user to create a unique number to get generated whenever a new record is inserted into the table.
This keyword is usually required whenever PRIMARY KEY in SQL is used.

AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword can be used in SQL SERVER.

Q113. What is a Datawarehouse?

Datawarehouse refers to a central repository of data where the data is assembled from multiple sources of information. Those data are consolidated, transformed and made available for the mining as well as online processing. Warehouse data also have a subset of data called Data Marts.

Q114. What are the different authentication modes in SQL Server? How can it be changed?

Windows mode and Mixed Mode – SQL and Windows. You can go to the below steps to change authentication mode in SQL Server:

  • Click Start> Programs> Microsoft SQL Server and click SQL Enterprise Manager to run SQL Enterprise Manager from the Microsoft SQL Server program group.
  • Then select the server from the Tools menu.
  • Select SQL Server Configuration Properties, and choose the Security page.

Q115. What are STUFF and REPLACE function?

STUFF Function :This function is used to overwrite existing character or inserts a string into another string. Syntax:
STUFF(string_expression,start, length, replacement_characters)
where,
string_expression :it is the string that will have characters substitutedstart: This refers to the starting position
length :It refers to the number of characters in the string which are substituted.replacement_string :They are the new characters which are injected in the string.

REPLACE function :This function is used to replace the existing characters of all the occurrences. Syntax:
REPLACE (string_expression, search_string, replacement_string)
Here every search_string in the string_expression will be replaced with the replacement_string.

So this brings us to the end of the SQL interview questions blog. I hope this set of SQL Interview Questions will help you ace your job interview. All the best for your interview!

Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on SQL, you can opt for a structured training from edureka! Click below to know more.

Check out this MySQL DBA Certification Training by Edureka, a trusted online learning company with a network von mehr als 250.000 zufriedenen Lernenden auf der ganzen Welt. Dieser Kurs schult Sie in den Kernkonzepten und fortgeschrittenen Tools und Techniken zur Verwaltung von Daten und zur Verwaltung der MySQL-Datenbank. It includes hands-on learning on concepts like MySQL Workbench, MySQL Server, Data Modeling, MySQL Connector, Database Design, MySQL Command line, MySQL Functions etc. End of the training you will be able to create and administer your own MySQL Database and manage data.

Haben Sie eine Frage an uns? Please mention it in the comments section of this “ SQL Interview Questions” blog and we will get back to you as soon as possible.