RDBMS AND MYSQL

RDBMS AND MYSQL

Q. What is the Difference between Data and Information?

In English

DataInformation
Raw facts and figures.Processed and organized data.
Has no clear meaning on its own.Has meaning and purpose.
Example: numbers, symbols, names.Example: student marks converted into result.
Can be in the form of text, numbers, images, or audio.Always useful for decision-making.
Collected from various sources.Generated after processing data.
May contain errors or redundancy.Usually accurate and summarized.
Cannot help in decision-making directly.Helps in decision-making.
Input for processing.Output of processing.

हिन्दी में

डेटाइन्फॉर्मेशन
कच्चे तथ्य और आँकड़े।संसाधित और व्यवस्थित डेटा।
अपने आप में कोई स्पष्ट अर्थ नहीं।अर्थपूर्ण और उद्देश्यपूर्ण होता है।
उदाहरण: संख्या, चिन्ह, नाम।उदाहरण: विद्यार्थियों के अंक से बना परिणाम।
टेक्स्ट, संख्या, इमेज या ऑडियो के रूप में हो सकता है।हमेशा निर्णय लेने में सहायक।
विभिन्न स्रोतों से इकट्ठा किया जाता है।डेटा प्रोसेस करने के बाद बनता है।
इसमें गलती या दोहराव हो सकता है।आमतौर पर सही और संक्षिप्त होता है।
सीधे निर्णय लेने में मददगार नहीं।निर्णय लेने में मददगार।
प्रोसेसिंग के लिए इनपुट।प्रोसेसिंग का आउटपुट।

Q. What is Database?

In English

A database is an organized collection of data that can be easily accessed, managed, and updated. It stores data in a structured form so that it can be used quickly and efficiently. Databases are used in banks, schools, offices, hospitals, and almost every field.

  • Stores large amount of data systematically.
  • Makes searching, updating, and deleting data easy.
  • Provides security and reduces data duplication.
  • Managed by Database Management System (DBMS).
  • Examples: MySQL, Oracle, MS Access.

हिन्दी में

डेटाबेस एक संगठित डाटा का संग्रह है, जिसे आसानी से एक्सेस, प्रबंधित और अपडेट किया जा सकता है। इसमें डाटा को व्यवस्थित रूप से रखा जाता है ताकि उसे जल्दी और प्रभावी ढंग से उपयोग किया जा सके। डेटाबेस का प्रयोग बैंक, स्कूल, दफ्तर, अस्पताल और लगभग हर क्षेत्र में होता है।

  • बड़े पैमाने पर डाटा को व्यवस्थित रूप से संग्रह करता है।
  • डाटा को खोजना, बदलना और हटाना आसान बनाता है।
  • सुरक्षा प्रदान करता है और डाटा की पुनरावृत्ति कम करता है।
  • डेटाबेस मैनेजमेंट सिस्टम (DBMS) द्वारा प्रबंधित किया जाता है।
  • उदाहरण: MySQL, Oracle, MS Access।

Q. What is RDBMS and its Advantages and Disadvantages?

In English

RDBMS stands for Relational Database Management System. It stores data in the form of tables (rows and columns) and allows relationships between them. It is widely used in modern applications like banking, education, business, etc. Examples are MySQL, Oracle, SQL Server.

Advantages:

  • Stores data in table format, easy to understand.
  • Maintains relationships between different data.
  • Reduces data redundancy.
  • Provides data security and integrity.
  • Supports multiple users at the same time.
  • Easy to update, search, and retrieve data.

Disadvantages:

  • Complex to set up and maintain.
  • Requires more memory and resources.
  • Expensive compared to simple database systems.
  • Performance may be slow for very large data if not managed properly.

हिन्दी में

RDBMS का पूरा नाम है Relational Database Management System। इसमें डेटा को तालिकाओं (rows और columns) के रूप में संग्रहित किया जाता है और अलग-अलग तालिकाओं के बीच संबंध बनाए जाते हैं। इसका उपयोग बैंकिंग, शिक्षा, व्यापार आदि क्षेत्रों में होता है। उदाहरण: MySQL, Oracle, SQL Server।

फायदे:

  • डेटा को टेबल के रूप में संग्रहित करता है, समझना आसान।
  • अलग-अलग डेटा के बीच संबंध बनाए रखता है।
  • डेटा की पुनरावृत्ति कम करता है।
  • डेटा की सुरक्षा और शुद्धता प्रदान करता है।
  • एक ही समय में कई उपयोगकर्ताओं का समर्थन करता है।
  • डेटा को बदलना, खोजना और प्राप्त करना आसान।

नुकसान:

  • सेटअप और प्रबंधन जटिल।
  • अधिक मेमोरी और संसाधनों की ज़रूरत।
  • साधारण डेटाबेस की तुलना में महंगा।
  • बहुत बड़े डेटा पर सही ढंग से प्रबंधन न होने पर धीमा हो सकता है।

Q. Difference between Traditional File System and DBMS

In English

Traditional File SystemDBMS (Database Management System)
Stores data in separate files.Stores data in structured databases.
Data is scattered and difficult to manage.Data is centralized and well managed.
High data redundancy (repetition).Low data redundancy.
Security is very less.Provides strong data security.
Searching data is slow.Searching data is fast.
Difficult to update or modify data.Easy to update and modify data.
Backup and recovery not easy.Provides backup and recovery options.
Supports single user mostly.Supports multiple users at the same time.

हिन्दी में

पारंपरिक फ़ाइल सिस्टमDBMS (डेटाबेस मैनेजमेंट सिस्टम)
डेटा अलग-अलग फ़ाइलों में संग्रहित होता है।डेटा संरचित डेटाबेस में संग्रहित होता है।
डेटा बिखरा हुआ और प्रबंधन कठिन।डेटा केंद्रीकृत और व्यवस्थित।
डेटा की पुनरावृत्ति अधिक।डेटा की पुनरावृत्ति कम।
सुरक्षा बहुत कम।मज़बूत डेटा सुरक्षा प्रदान करता है।
डेटा खोजना धीमा।डेटा खोजना तेज़।
डेटा अपडेट या बदलना कठिन।डेटा अपडेट या बदलना आसान।
बैकअप और रिकवरी आसान नहीं।बैकअप और रिकवरी की सुविधा देता है।
ज़्यादातर एक ही उपयोगकर्ता का समर्थन करता है।एक साथ कई उपयोगकर्ताओं का समर्थन करता है।

Q. What are the Three Tier Structure of DBMS?

In English

The three-tier structure of DBMS divides the database system into three layers to provide abstraction, security, and efficient management.

1. Presentation Tier (External Level):

  • Closest to the user.
  • Shows only the required data in a simple format.
  • Hides the internal details.
  • Example: A student sees only his marksheet on a portal, not the whole database.

2. Application Tier (Conceptual Level):

  • Acts as a bridge between user and database.
  • Defines the structure of the whole database.
  • Manages relationships, rules, and security.
  • Example: The education system stores how students, subjects, and marks are related.

3. Database Tier (Internal Level):

  • Lowest level of abstraction.
  • Deals with physical storage of data.
  • Manages indexing, performance, and storage space.
  • Example: How the marks of students are stored in hard disk using rows, columns, and indexing.

हिन्दी में

DBMS की three-tier संरचना डेटाबेस को तीन स्तरों में बाँटती है ताकि सुरक्षा, अमूर्तता और कुशल प्रबंधन हो सके।

1. प्रस्तुति स्तर (External Level):

  • यह उपयोगकर्ता के सबसे पास होता है।
  • केवल आवश्यक डेटा को सरल रूप में दिखाता है।
  • आंतरिक विवरण को छिपाता है।
  • उदाहरण: छात्र पोर्टल पर सिर्फ अपना मार्कशीट देखता है, पूरा डेटाबेस नहीं।

2. अनुप्रयोग स्तर (Conceptual Level):

  • उपयोगकर्ता और डेटाबेस के बीच सेतु का काम करता है।
  • पूरे डेटाबेस की संरचना को परिभाषित करता है।
  • संबंध, नियम और सुरक्षा को संभालता है।
  • उदाहरण: शिक्षा प्रणाली में यह परिभाषित करता है कि छात्र, विषय और अंक आपस में कैसे जुड़े हैं।

3. डेटाबेस स्तर (Internal Level):

  • यह सबसे निचला स्तर होता है।
  • डेटा का भौतिक भंडारण करता है।
  • इंडेक्सिंग, प्रदर्शन और संग्रहण का प्रबंधन करता है।
  • उदाहरण: छात्रों के अंक हार्ड डिस्क में rows, columns और indexing द्वारा कैसे संग्रहित होते हैं।

Q. Who is DBA and What are Different Roles and Responsibilities of DBA?

In English

A DBA (Database Administrator) is a person responsible for managing, maintaining, and securing the database system. DBA ensures smooth functioning of the database for all users.

Roles and Responsibilities of DBA:

  • Database Design: Creates database structure (tables, relationships, constraints).
  • Database Security: Provides access rights and prevents unauthorized use.
  • Backup and Recovery: Takes regular backups and restores data in case of failure.
  • Performance Monitoring: Ensures queries run fast and database works efficiently.
  • Data Integrity: Maintains accuracy and consistency of data.
  • User Management: Creates and manages user accounts.
  • Database Upgrades: Installs new versions and applies patches.
  • Troubleshooting: Solves problems like crashes, corruption, or slow performance.

हिन्दी में

DBA (Database Administrator) वह व्यक्ति है जो डेटाबेस सिस्टम का प्रबंधन, देखभाल और सुरक्षा करता है। DBA यह सुनिश्चित करता है कि सभी उपयोगकर्ताओं के लिए डेटाबेस सही और सुचारू रूप से कार्य करे।

DBA की भूमिकाएँ और ज़िम्मेदारियाँ:

  • डेटाबेस डिज़ाइन: डेटाबेस की संरचना (टेबल्स, संबंध, constraints) बनाता है।
  • डेटाबेस सुरक्षा: उपयोगकर्ताओं को सही अधिकार देता है और अनधिकृत पहुँच रोकता है।
  • बैकअप और रिकवरी: नियमित रूप से बैकअप लेता है और खराबी पर डेटा वापस लाता है।
  • प्रदर्शन निगरानी: यह सुनिश्चित करता है कि queries तेज़ चलें और डेटाबेस कुशलता से काम करे।
  • डेटा अखंडता: डेटा की शुद्धता और स्थिरता बनाए रखता है।
  • उपयोगकर्ता प्रबंधन: यूज़र अकाउंट बनाता और नियंत्रित करता है।
  • डेटाबेस अपग्रेड: नए संस्करण और patches इंस्टॉल करता है।
  • समस्या समाधान: database crash, corruption या slow performance जैसी समस्याओं को हल करता है।

Q. What do you mean by SQL? What are Characteristics of SQL?

In English

SQL (Structured Query Language) is a standard language used to store, manage, and retrieve data in a relational database. It is widely used in almost all database systems like MySQL, Oracle, and SQL Server.

Characteristics of SQL:

  • Simple Language: Easy to learn and use with simple English-like commands.
  • Data Definition: Allows creating, modifying, and deleting database objects like tables.
  • Data Manipulation: Provides commands to insert, update, delete, and retrieve data.
  • Data Control: Manages user permissions and access rights.
  • Portability: SQL works with different database systems.
  • Interactive: Provides quick responses to queries.
  • Standardized: Accepted as an international standard by ANSI and ISO.
  • Supports Transactions: Ensures data accuracy with commit and rollback features.

हिन्दी में

SQL (Structured Query Language) एक मानक भाषा है जिसका उपयोग रिलेशनल डेटाबेस में डेटा को संग्रहित, प्रबंधित और प्राप्त करने के लिए किया जाता है। इसका प्रयोग लगभग सभी डेटाबेस सिस्टम जैसे MySQL, Oracle, SQL Server में होता है।

SQL की विशेषताएँ:

  • सरल भाषा: सीखने और उपयोग करने में आसान, साधारण अंग्रेज़ी जैसे commands।
  • डेटा परिभाषा: डेटाबेस ऑब्जेक्ट जैसे टेबल बनाना, बदलना और हटाना।
  • डेटा प्रबंधन: डेटा को insert, update, delete और retrieve करने की सुविधा।
  • डेटा नियंत्रण: उपयोगकर्ताओं के अधिकार और permissions नियंत्रित करता है।
  • पोर्टेबिलिटी: अलग-अलग डेटाबेस सिस्टम पर काम करता है।
  • इंटरैक्टिव: queries के तेज़ जवाब देता है।
  • मानकीकृत: ANSI और ISO द्वारा अंतर्राष्ट्रीय मानक के रूप में स्वीकार।
  • ट्रांज़ैक्शन समर्थन: commit और rollback से डेटा की शुद्धता सुनिश्चित करता है।

Q. What are Different Datatypes in SQL?

In English

In SQL, datatypes define the type of data that can be stored in a column of a table. Each datatype specifies the kind of values like numbers, characters, or dates.

Different Datatypes in SQL:

  • INT / INTEGER: Stores whole numbers (e.g., 10, -25).
  • FLOAT / DOUBLE / REAL: Stores decimal or floating-point numbers (e.g., 12.5, 3.141).
  • CHAR(n): Stores fixed-length character strings (e.g., ‘YES’, ‘NO’).
  • VARCHAR(n): Stores variable-length character strings (e.g., ‘Hello’, ‘OpenAI’).
  • TEXT: Stores long text values.
  • DATE: Stores calendar dates (YYYY-MM-DD).
  • TIME: Stores time (HH\:MM\:SS).
  • DATETIME / TIMESTAMP: Stores both date and time together.
  • BOOLEAN: Stores logical values TRUE or FALSE.

हिन्दी में

SQL में डेटा टाइप्स यह तय करते हैं कि किसी टेबल के कॉलम में किस प्रकार का डेटा संग्रहित किया जा सकता है। हर डेटा टाइप अलग-अलग प्रकार के मान जैसे संख्या, अक्षर या तारीख को दर्शाता है।

SQL में विभिन्न डेटा टाइप्स:

  • INT / INTEGER: पूर्णांक संख्या संग्रहित करता है (जैसे 10, -25)।
  • FLOAT / DOUBLE / REAL: दशमलव या floating-point संख्या संग्रहित करता है (जैसे 12.5, 3.141)।
  • CHAR(n): निश्चित लंबाई वाले अक्षर संग्रहित करता है (जैसे ‘YES’, ‘NO’)।
  • VARCHAR(n): बदलती लंबाई वाले अक्षर संग्रहित करता है (जैसे ‘Hello’, ‘OpenAI’)।
  • TEXT: लंबा टेक्स्ट डेटा संग्रहित करता है।
  • DATE: कैलेंडर तिथि संग्रहित करता है (YYYY-MM-DD)।
  • TIME: समय संग्रहित करता है (HH\:MM\:SS)।
  • DATETIME / TIMESTAMP: तिथि और समय दोनों संग्रहित करता है।
  • BOOLEAN: तार्किक मान TRUE या FALSE संग्रहित करता है।

Q. Difference Between CHAR and VARCHAR Data Types

In English

CHARVARCHAR
Stores fixed-length character strings.Stores variable-length character strings.
Length is always the same, unused space is filled with spaces.Length depends on the actual number of characters entered.
Faster in performance because size is fixed.Slower compared to CHAR as it handles varying length.
Wastes memory if data is smaller than defined size.Saves memory as it uses only required space.
Example: CHAR(10) will always store 10 characters (e.g., ‘CAT ‘).Example: VARCHAR(10) stores only actual characters (e.g., ‘CAT’).

हिन्दी में

CHARVARCHAR
निश्चित लंबाई वाले अक्षर संग्रहित करता है।बदलती लंबाई वाले अक्षर संग्रहित करता है।
लंबाई हमेशा समान रहती है, खाली जगह spaces से भर दी जाती है।लंबाई केवल डाले गए अक्षरों पर निर्भर करती है।
प्रदर्शन तेज़ होता है क्योंकि आकार निश्चित है।CHAR की तुलना में थोड़ा धीमा क्योंकि यह बदलती लंबाई संभालता है।
यदि डेटा छोटा है तो मेमोरी व्यर्थ जाती है।मेमोरी बचाता है क्योंकि केवल ज़रूरी जगह लेता है।
उदाहरण: CHAR(10) हमेशा 10 अक्षर रखेगा (जैसे ‘CAT ‘)।उदाहरण: VARCHAR(10) केवल वास्तविक अक्षर रखेगा (जैसे ‘CAT’)।

Q. What do you mean by Constraints?

In English

In SQL, constraints are rules applied on columns of a table to ensure accuracy, validity, and reliability of data. They restrict the type of data that can be stored in a table.

Types of Constraints:

  • NOT NULL: Ensures a column cannot have NULL value.
  • UNIQUE: Ensures all values in a column are unique.
  • PRIMARY KEY: Uniquely identifies each record in a table (NOT NULL + UNIQUE).
  • FOREIGN KEY: Maintains relationship between two tables.
  • CHECK: Ensures values meet specific conditions.
  • DEFAULT: Provides a default value if no value is specified.

हिन्दी में

SQL में constraints वे नियम होते हैं जो किसी टेबल के कॉलम पर लगाए जाते हैं ताकि डेटा सही, वैध और भरोसेमंद रहे। ये नियंत्रित करते हैं कि टेबल में किस प्रकार का डेटा संग्रहित हो सकता है।

Constraints के प्रकार:

  • NOT NULL: कॉलम में NULL मान नहीं हो सकता।
  • UNIQUE: कॉलम के सभी मान अलग-अलग होने चाहिए।
  • PRIMARY KEY: हर रिकॉर्ड को uniquely पहचानता है (NOT NULL + UNIQUE)।
  • FOREIGN KEY: दो टेबल के बीच संबंध बनाए रखता है।
  • CHECK: यह सुनिश्चित करता है कि मान विशेष शर्त पूरी करें।
  • DEFAULT: यदि कोई मान न दिया जाए तो डिफ़ॉल्ट मान देता है।

Q. What is Domain Integrity Constraint?

In English

A Domain Integrity Constraint ensures that the values entered in a column are valid and within a defined range or type. It restricts the type, format, or range of values that can be stored in a column.

Examples:

  • Age column should accept only numbers between 1 and 120.
  • Gender column should allow only ‘Male’, ‘Female’, or ‘Other’.
  • Date of Birth column must be in valid date format.

This helps in maintaining correctness and validity of data in a database.


हिन्दी में

Domain Integrity Constraint यह सुनिश्चित करता है कि किसी कॉलम में डाले गए मान सही हों और एक निश्चित सीमा या प्रकार के भीतर हों। यह मानों के प्रकार, प्रारूप या सीमा को नियंत्रित करता है।

उदाहरण:

  • Age कॉलम में केवल 1 से 120 के बीच की संख्या होनी चाहिए।
  • Gender कॉलम में केवल ‘Male’, ‘Female’ या ‘Other’ की अनुमति हो।
  • Date of Birth कॉलम में मान्य तारीख का प्रारूप होना चाहिए।

यह डेटाबेस में डेटा की शुद्धता और वैधता बनाए रखने में मदद करता है।

Q. What is Referential Integrity Constraint?

In English

A Referential Integrity Constraint ensures that the relationship between two tables remains consistent. It is applied using a Foreign Key. It makes sure that a value in one table corresponds to a valid value in another table.

Examples:

  • If a Student table has a Class_ID as foreign key, then that value must exist in the Class table.
  • If a record in the parent table is deleted, related child records must be handled (either deleted or restricted).

This avoids invalid references and maintains consistency between tables.


हिन्दी में

Referential Integrity Constraint यह सुनिश्चित करता है कि दो टेबलों के बीच संबंध सही और सुसंगत रहें। इसे Foreign Key के द्वारा लागू किया जाता है। यह सुनिश्चित करता है कि एक टेबल का मान दूसरी टेबल के मान से मेल खाए।

उदाहरण:

  • यदि Student टेबल में Class_ID foreign key है, तो वह मान Class टेबल में मौजूद होना चाहिए।
  • यदि parent टेबल से कोई रिकॉर्ड हटाया जाता है, तो उससे जुड़े child रिकॉर्ड को या तो हटाना होगा या रोका जाएगा।

इससे गलत references नहीं बनते और टेबलों में consistency बनी रहती है।

Q. What do you mean by DML, DDL, DCL, TCL?

In English

In SQL, commands are divided into different categories based on their purpose.

  • DDL (Data Definition Language):
    Used to define and manage database structure.
    Examples: CREATE, ALTER, DROP, TRUNCATE.
  • DML (Data Manipulation Language):
    Used to insert, update, delete, and retrieve data.
    Examples: INSERT, UPDATE, DELETE, SELECT.
  • DCL (Data Control Language):
    Used to control access and permissions of users.
    Examples: GRANT, REVOKE.
  • TCL (Transaction Control Language):
    Used to manage transactions and maintain data integrity.
    Examples: COMMIT, ROLLBACK, SAVEPOINT.

हिन्दी में

SQL में commands को उनके उपयोग के आधार पर अलग-अलग भागों में बाँटा गया है।

  • DDL (Data Definition Language):
    डेटाबेस की संरचना बनाने और प्रबंधित करने के लिए।
    उदाहरण: CREATE, ALTER, DROP, TRUNCATE
  • DML (Data Manipulation Language):
    डेटा जोड़ने, बदलने, हटाने और प्राप्त करने के लिए।
    उदाहरण: INSERT, UPDATE, DELETE, SELECT
  • DCL (Data Control Language):
    उपयोगकर्ताओं की पहुँच और permissions नियंत्रित करने के लिए।
    उदाहरण: GRANT, REVOKE
  • TCL (Transaction Control Language):
    ट्रांज़ैक्शन प्रबंधित करने और डेटा की शुद्धता बनाए रखने के लिए।
    उदाहरण: COMMIT, ROLLBACK, SAVEPOINT

Q. What do you mean by Table? How to Create Table in SQL?

In English

A Table in SQL is a collection of data organized in rows and columns. Each row represents a record, and each column represents a field or attribute of that record. Tables are the basic building blocks of a database.

Example: A Student table can have columns like Roll_No, Name, Class, and Marks.

Creating a Table in SQL:

CREATE TABLE Student (
   Roll_No INT PRIMARY KEY,
   Name VARCHAR(50),
   Class VARCHAR(20),
   Marks INT
);

This command creates a table named Student with four columns.


हिन्दी में

SQL में Table डेटा का संग्रह है जिसे rows और columns के रूप में संगठित किया जाता है। हर row एक रिकॉर्ड को दर्शाता है और हर column उस रिकॉर्ड के गुण (attribute) को। टेबल डेटाबेस की मूल इकाई होती है।

उदाहरण: Student टेबल में कॉलम हो सकते हैं – Roll_No, Name, Class, और Marks

SQL में Table बनाना:

CREATE TABLE Student (
   Roll_No INT PRIMARY KEY,
   Name VARCHAR(50),
   Class VARCHAR(20),
   Marks INT
);

यह command Student नाम का table बनाएगा जिसमें चार कॉलम होंगे।

Q. What is Function of SELECT Command?

In English

The SELECT command in SQL is used to retrieve data from one or more tables in a database. It allows users to view specific columns, rows, or apply conditions to filter data.

Functions of SELECT command:

  • Retrieves all or selected columns from a table.
  • Filters records using WHERE clause.
  • Sorts data using ORDER BY.
  • Combines data from multiple tables using JOIN.
  • Performs calculations using aggregate functions like SUM(), AVG(), COUNT().
  • Groups records using GROUP BY.

Example:

SELECT Name, Marks FROM Student WHERE Class = '12th';

This query shows names and marks of students from class 12th.


हिन्दी में

SQL में SELECT command का उपयोग डेटाबेस की एक या अधिक टेबल से डेटा प्राप्त करने के लिए किया जाता है। इससे उपयोगकर्ता विशेष कॉलम, पंक्तियाँ या शर्त लगाकर डेटा देख सकते हैं।

SELECT command के कार्य:

  • टेबल से सभी या कुछ चुने हुए कॉलम निकालना।
  • WHERE clause से रिकॉर्ड फ़िल्टर करना।
  • ORDER BY से डेटा को क्रमबद्ध करना।
  • कई टेबलों से डेटा जोड़ना (JOIN के द्वारा)।
  • SUM(), AVG(), COUNT() जैसे aggregate functions से गणना करना।
  • GROUP BY से रिकॉर्ड को समूह में बाँटना।

उदाहरण:

SELECT Name, Marks FROM Student WHERE Class = '12th';

यह query केवल 12वीं कक्षा के छात्रों के नाम और अंक दिखाएगी।

Q. How can you insert rows in a table?

In English

In SQL, we use the INSERT INTO command to add new rows of data into a table.

Methods to insert rows:

  1. Insert values into all columns
INSERT INTO Student VALUES (1, 'Rahul', '12th', 85);

👉 This will insert a new row in the Student table with RollNo = 1, Name = Rahul, Class = 12th, Marks = 85.

  1. Insert values into selected columns
INSERT INTO Student (RollNo, Name, Marks) VALUES (2, 'Anita', 90);

👉 Here, only RollNo, Name, and Marks are inserted. Class will remain NULL if not given.

  1. Insert multiple rows at once
INSERT INTO Student (RollNo, Name, Class, Marks)  
VALUES  
(3, 'Sohan', '11th', 78),  
(4, 'Meena', '12th', 92);

👉 This will insert two rows together.


हिन्दी में

SQL में किसी टेबल में नई पंक्ति (row) जोड़ने के लिए INSERT INTO command का उपयोग किया जाता है।

Rows insert करने के तरीके:

  1. सभी कॉलम में मान डालना
INSERT INTO Student VALUES (1, 'Rahul', '12th', 85);

👉 यह Student टेबल में एक नई पंक्ति जोड़ देगा।

  1. चुने हुए कॉलम में मान डालना
INSERT INTO Student (RollNo, Name, Marks) VALUES (2, 'Anita', 90);

👉 यहाँ Class नहीं दी गई है, तो वह NULL रहेगी।

  1. एक साथ कई rows डालना
INSERT INTO Student (RollNo, Name, Class, Marks)  
VALUES  
(3, 'Sohan', '11th', 78),  
(4, 'Meena', '12th', 92);

👉 यह दो rows एक साथ insert करेगा।


Q. What is the use of DISTINCT clause in SELECT statement?

In English

  • The DISTINCT clause in SQL is used to remove duplicate values from the result set of a query.
  • It ensures that only unique values are returned.

Syntax:

SELECT DISTINCT column_name FROM table_name;

Example:

Suppose we have a table Student:

RollNoNameClass
1Rahul12th
2Anita11th
3Sohan12th
4Meena10th
5Rahul12th

👉 Query:

SELECT DISTINCT Name FROM Student;

👉 Output:

Name
Rahul
Anita
Sohan
Meena

Here, Rahul appeared twice in the table but only once in the result because of DISTINCT.


हिन्दी में

  • SQL में DISTINCT clause का उपयोग duplicate (दोहराए हुए) मानों को हटाने के लिए किया जाता है।
  • यह केवल unique values ही वापस करता है।

Syntax:

SELECT DISTINCT column_name FROM table_name;

उदाहरण:

Student टेबल में ऊपर दिए गए डाटा से अगर हम चलाएँ:

SELECT DISTINCT Name FROM Student;

👉 परिणाम:

Name
Rahul
Anita
Sohan
Meena

यहाँ Rahul दो बार था, लेकिन परिणाम में केवल एक बार आया क्योंकि DISTINCT लगाया गया है।


Q. What is the purpose of WHERE clause with SELECT statement?

In English

  • The WHERE clause in SQL is used to filter records from a table.
  • It is used with the SELECT statement to get only those rows which meet a specific condition.
  • Without WHERE, all rows of the table are returned.

Syntax:

SELECT column_name FROM table_name WHERE condition;

Example:

Suppose we have a table Student:

RollNoNameClassMarks
1Rahul12th85
2Anita11th70
3Sohan12th90
4Meena10th60
SELECT Name, Marks FROM Student WHERE Marks > 75;

Output:

NameMarks
Rahul85
Sohan90

हिन्दी में

  • SQL में WHERE clause का उपयोग टेबल से records को filter करने के लिए किया जाता है।
  • यह SELECT statement के साथ प्रयोग होता है ताकि केवल वही rows वापस मिलें जो condition को पूरा करती हैं।
  • अगर WHERE नहीं लगाया जाता, तो पूरी टेबल की rows वापस आती हैं।

Syntax:

SELECT column_name FROM table_name WHERE condition;

उदाहरण:

ऊपर दिए गए Student टेबल से:

SELECT Name, Marks FROM Student WHERE Marks > 75;

परिणाम:

NameMarks
Rahul85
Sohan90

Q. What is the function of ORDER BY clause?

In English

  • The ORDER BY clause in SQL is used to arrange the result set of a query in ascending or descending order.
  • By default, it sorts data in ascending order (ASC).
  • For descending order, we use the keyword DESC.
  • It can be applied on one or more columns.

Syntax:

SELECT column_name FROM table_name ORDER BY column_name ASC|DESC;

Example:

Suppose we have a table Student:

RollNoNameMarks
1Rahul85
2Anita90
3Sohan75
4Meena95
5Ramesh80
SELECT Name, Marks FROM Student ORDER BY Marks DESC;

Output:

NameMarks
Meena95
Anita90
Rahul85
Ramesh80
Sohan75

हिन्दी में

  • SQL में ORDER BY clause का उपयोग query के result को ascending या descending order में व्यवस्थित करने के लिए किया जाता है।
  • Default रूप से यह data को ascending order (ASC) में sort करता है।
  • Descending order के लिए DESC keyword का प्रयोग किया जाता है।
  • इसे एक या एक से अधिक columns पर लागू किया जा सकता है।

Syntax:

SELECT column_name FROM table_name ORDER BY column_name ASC|DESC;

उदाहरण:

ऊपर दिए गए Student टेबल से:

SELECT Name, Marks FROM Student ORDER BY Marks DESC;

परिणाम:

NameMarks
Meena95
Anita90
Rahul85
Ramesh80
Sohan75

Q. What is the use of AND, OR and NOT operator in SQL?

In English

These operators are used in the WHERE clause to filter records based on conditions.

  • AND → Returns records when all conditions are true.
  • OR → Returns records when any one condition is true.
  • NOT → Returns records when the condition is not true.

Syntax:

SELECT column_name FROM table_name WHERE condition1 AND/OR/NOT condition2;

Example (Student Table):

RollNoNameMarksCity
1Rahul85Delhi
2Anita90Mumbai
3Sohan75Delhi
4Meena95Kolkata
5Ramesh80Mumbai
-- Using AND
SELECT Name, Marks FROM Student WHERE Marks > 80 AND City = 'Delhi';

Output: Rahul (85)

-- Using OR
SELECT Name, City FROM Student WHERE City = 'Delhi' OR City = 'Mumbai';

Output: Rahul, Anita, Sohan, Ramesh

-- Using NOT
SELECT Name, City FROM Student WHERE NOT City = 'Delhi';

Output: Anita, Meena, Ramesh


हिन्दी में

ये ऑपरेटर्स WHERE clause में conditions के आधार पर records को filter करने के लिए उपयोग होते हैं।

  • AND → Record तभी मिलेगा जब सभी conditions सही हों।
  • OR → Record तब मिलेगा जब कोई एक condition सही हो।
  • NOT → Record तब मिलेगा जब condition सही न हो

Syntax:

SELECT column_name FROM table_name WHERE condition1 AND/OR/NOT condition2;

उदाहरण (Student Table):

-- AND का प्रयोग
SELECT Name, Marks FROM Student WHERE Marks > 80 AND City = 'Delhi';

Result: Rahul (85)

-- OR का प्रयोग
SELECT Name, City FROM Student WHERE City = 'Delhi' OR City = 'Mumbai';

Result: Rahul, Anita, Sohan, Ramesh

-- NOT का प्रयोग
SELECT Name, City FROM Student WHERE NOT City = 'Delhi';

Result: Anita, Meena, Ramesh

Q. Why BETWEEN operator is used?

In English

The BETWEEN operator is used in SQL to filter records within a specific range of values. It works for numbers, text, and dates. The range includes both the starting and ending values.

Syntax:

SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;

Example (Student Table):

RollNoNameMarks
1Rahul85
2Anita90
3Sohan75
4Meena95
5Ramesh60
SELECT Name, Marks FROM Student WHERE Marks BETWEEN 80 AND 90;

Output: Rahul (85), Anita (90)


हिन्दी में

BETWEEN operator का उपयोग SQL में records को एक निर्धारित सीमा (range) के अंदर लाने के लिए किया जाता है। यह numbers, text और dates पर काम करता है। इसमें शुरुआती और अंतिम दोनों values शामिल होती हैं।

Syntax:

SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;

उदाहरण (Student Table):

SELECT Name, Marks FROM Student WHERE Marks BETWEEN 80 AND 90;

Result: Rahul (85), Anita (90)

Q. How can you remove a table in database?

In English

To remove a table from a database, the DROP TABLE command is used. This command permanently deletes the table along with all its data, structure, and indexes. Once removed, the table cannot be recovered unless backed up.

Syntax:

DROP TABLE table_name;

Example:

DROP TABLE Student;

This will delete the table named Student from the database.


हिन्दी में

डेटाबेस से किसी टेबल को हटाने के लिए DROP TABLE कमांड का प्रयोग किया जाता है। यह कमांड टेबल के सभी डेटा, संरचना और indexes को स्थायी रूप से हटा देता है। हटाने के बाद टेबल वापस नहीं मिल सकता जब तक उसका backup न हो।

Syntax:

DROP TABLE table_name;

उदाहरण:

DROP TABLE Student;

यह कमांड डेटाबेस से Student नाम की टेबल को हटा देगा।

Q. How can you create users in SQL?

In English

In SQL, new users are created using the CREATE USER command. This command allows the database administrator to add a new user account with a username and password. After creating a user, permissions must be granted for accessing the database.

Syntax:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Example:

CREATE USER 'john'@'localhost' IDENTIFIED BY 'john123';

This will create a new user john with password john123, who can access the database from the local system.


हिन्दी में

SQL में नया user बनाने के लिए CREATE USER कमांड का प्रयोग किया जाता है। यह कमांड डेटाबेस में नया यूज़र अकाउंट username और password के साथ जोड़ने के लिए होता है। यूज़र बनाने के बाद उसे database access करने के लिए permissions देनी पड़ती हैं।

Syntax:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

उदाहरण:

CREATE USER 'john'@'localhost' IDENTIFIED BY 'john123';

यह कमांड एक नया user john बनाएगा जिसका password john123 होगा, और जो केवल local system से database access कर सकेगा।

Q. How can you delete user accounts in SQL?

In English

To delete a user account in SQL, the DROP USER command is used. This command removes the user and all their privileges from the database. Once deleted, the user can no longer access the database.

Syntax:

DROP USER 'username'@'host';

Example:

DROP USER 'john'@'localhost';

This will delete the user john who was created for the local system.


हिन्दी में

SQL में किसी user account को हटाने के लिए DROP USER कमांड का उपयोग किया जाता है। यह कमांड user और उसकी सभी privileges को database से हटा देता है। हटाने के बाद वह user database को access नहीं कर सकता।

Syntax:

DROP USER 'username'@'host';

उदाहरण:

DROP USER 'john'@'localhost';

यह कमांड john नाम के user को हटा देगा, जो local system से database access करता था।

Q. What is Database and Database Management System?

In English

Database:
A database is an organized collection of data that can be easily accessed, managed, and updated. Data is stored in tables (rows and columns). Example: Student records, Banking system, Library system.

Database Management System (DBMS):
DBMS is software that helps to create, manage, and operate a database. It allows storing, retrieving, updating, and securing data efficiently. Examples: MySQL, Oracle, MS Access, SQL Server.

Key Points:

  • Database stores data in an organized way.
  • DBMS is software to manage that database.
  • DBMS provides data security, integrity, and sharing.

हिन्दी में

Database:
Database एक संगठित संग्रह (organized collection) है जिसमें डेटा को आसानी से access, manage और update किया जा सकता है। डेटा तालिकाओं (rows और columns) में संग्रहित होता है। उदाहरण: Student records, Banking system, Library system।

Database Management System (DBMS):
DBMS एक software है जो database को बनाने, प्रबंधित करने और चलाने में मदद करता है। इसके द्वारा डेटा को store, retrieve, update और सुरक्षित किया जा सकता है। उदाहरण: MySQL, Oracle, MS Access, SQL Server।

मुख्य बिंदु:

  • Database डेटा को व्यवस्थित रूप से संग्रहित करता है।
  • DBMS उस database को प्रबंधित करने वाला software है।
  • DBMS डेटा की सुरक्षा, शुद्धता और sharing प्रदान करता है।

Q. What is Function? What are various kinds of functions in SQL?

In English

Function:
In SQL, a function is a pre-defined program that performs a specific task and returns a value. Functions help in simplifying queries, reducing complexity, and increasing reusability.

Kinds of Functions in SQL:

  1. Aggregate Functions
  • These functions work on a collection (group) of rows and return a single summarized value.
  • Commonly used in SELECT statements with GROUP BY.
  • Examples:
    • SUM(column) → Returns the total of values in a column.
    • AVG(column) → Returns the average of values.
    • COUNT(column) → Returns the number of rows.
    • MAX(column) → Returns the largest value.
    • MIN(column) → Returns the smallest value.

2. Scalar Functions

  • These functions work on a single value and return a single value.
  • Mostly used for string, numeric, or date operations.
  • Examples:
    • UCASE(text) / UPPER(text) → Converts text to uppercase.
    • LCASE(text) / LOWER(text) → Converts text to lowercase.
    • LEN(text) / LENGTH(text) → Returns length of string.
    • ROUND(number, decimals) → Rounds a number to specified decimals.
    • NOW() → Returns current system date and time.

3.String Functions

  • Used to manipulate or format strings.
  • Examples:
    • CONCAT(str1, str2) → Joins two or more strings.
    • SUBSTRING(str, start, length) → Extracts part of a string.
    • TRIM(text) → Removes spaces from beginning and end of a string.

4.Date and Time Functions

  • Used to perform operations on dates and time values.
  • Examples:
    • CURDATE() → Returns current date.
    • CURTIME() → Returns current time.
    • DATEADD() → Adds a value to a date.
    • DATEDIFF(date1, date2) → Finds difference between two dates.

हिन्दी में

Function:
SQL में function एक pre-defined प्रोग्राम होता है, जो किसी विशेष कार्य को करता है और एक value लौटाता है। Functions queries को आसान, छोटा और उपयोगी बनाते हैं।

SQL में Functions के प्रकार:

  1. Aggregate Functions
  • ये functions rows के समूह (collection) पर काम करते हैं और एक summarized value लौटाते हैं।
  • इन्हें SELECT के साथ GROUP BY में अधिक उपयोग किया जाता है।
  • उदाहरण:
    • SUM(column) → कॉलम के मानों का कुल जोड़ देता है।
    • AVG(column) → औसत मान निकालता है।
    • COUNT(column) → rows की गिनती करता है।
    • MAX(column) → सबसे बड़ा मान देता है।
    • MIN(column) → सबसे छोटा मान देता है।
  1. Scalar Functions
  • ये functions एक single value पर काम करते हैं और एक value लौटाते हैं।
  • इन्हें string, numeric और date operations में प्रयोग किया जाता है।
  • उदाहरण:
    • UCASE(text) / UPPER(text) → text को uppercase में बदलता है।
    • LCASE(text) / LOWER(text) → text को lowercase में बदलता है।
    • LEN(text) / LENGTH(text) → string की लंबाई देता है।
    • ROUND(number, decimals) → संख्या को round करता है।
    • NOW() → वर्तमान तारीख और समय देता है।
  1. String Functions
  • Strings को manipulate या format करने के लिए उपयोग होते हैं।
  • उदाहरण:
    • CONCAT(str1, str2) → दो या अधिक strings को जोड़ना।
    • SUBSTRING(str, start, length) → string का हिस्सा निकालना।
    • TRIM(text) → शुरुआत और अंत के spaces हटाना।
  1. Date और Time Functions
  • तारीख और समय पर operations करने के लिए उपयोग होते हैं।
  • उदाहरण:
    • CURDATE() → वर्तमान तारीख देता है।
    • CURTIME() → वर्तमान समय देता है।
    • DATEADD() → किसी तारीख में मान जोड़ना।
    • DATEDIFF(date1, date2) → दो तारीखों का अंतर निकालना।


👉 Answer:

What do you mean by Constraints?

  • In SQL, constraints are rules applied on table columns.
  • They are used to ensure accuracy, validity, and reliability of data in a database.
  • Constraints restrict the type of data that can be stored in a column.
  • Example: A student’s age cannot be negative.

Different kinds of Constraints

  1. NOT NULL Constraint
  • Ensures that a column cannot have NULL values.
  • Example: CREATE TABLE Student( RollNo INT NOT NULL, Name VARCHAR(50) );
  1. UNIQUE Constraint
  • Ensures that all values in a column are unique.
  • Example: CREATE TABLE Student( RollNo INT UNIQUE, Name VARCHAR(50) );
  1. PRIMARY KEY Constraint
  • Combination of NOT NULL and UNIQUE.
  • Uniquely identifies each row in a table.
  • Example: CREATE TABLE Student( RollNo INT PRIMARY KEY, Name VARCHAR(50) );
  1. FOREIGN KEY Constraint
  • Creates a link between two tables.
  • Ensures that the value in one table matches a value in another table.
  • Example: CREATE TABLE Orders( OrderID INT PRIMARY KEY, StudentRollNo INT, FOREIGN KEY(StudentRollNo) REFERENCES Student(RollNo) );
  1. CHECK Constraint
  • Ensures that all values in a column satisfy a condition.
  • Example: CREATE TABLE Student( RollNo INT PRIMARY KEY, Age INT CHECK(Age >= 5) );
  1. DEFAULT Constraint
  • Provides a default value for a column when no value is given.
  • Example: CREATE TABLE Student( RollNo INT PRIMARY KEY, City VARCHAR(20) DEFAULT 'Delhi' );

In Short:

  • NOT NULL → No empty values.
  • UNIQUE → No duplicate values.
  • PRIMARY KEY → Unique + Not Null.
  • FOREIGN KEY → Connects two tables.
  • CHECK → Condition must be true.
  • DEFAULT → Assigns default value.

जी mere dost, अब मुझे याद है आपका format ✅ (पहले English फिर Hindi).
चलो मैं आपके दिए topic “Classification of MySQL Statements” को उसी format में लिखता हूँ।


Q. What are the Classification of MySQL Statements?

In English

MySQL statements are classified into the following categories:

  1. DDL (Data Definition Language):
  • Used to define and manage the structure of database objects.
  • Commands: CREATE, ALTER, DROP, TRUNCATE.
  1. DML (Data Manipulation Language):
  • Used to manipulate data stored in tables.
  • Commands: INSERT, UPDATE, DELETE, SELECT.
  1. DCL (Data Control Language):
  • Used to control access and permissions in the database.
  • Commands: GRANT, REVOKE.
  1. TCL (Transaction Control Language):
  • Used to manage database transactions.
  • Commands: COMMIT, ROLLBACK, SAVEPOINT.
  1. DQL (Data Query Language):
  • Used to retrieve data from the database.
  • Command: SELECT.

हिन्दी में

MySQL statements को निम्नलिखित वर्गों में बाँटा गया है:

  1. DDL (Data Definition Language):
  • डेटाबेस की संरचना को परिभाषित और प्रबंधित करने के लिए।
  • Commands: CREATE, ALTER, DROP, TRUNCATE.
  1. DML (Data Manipulation Language):
  • डेटाबेस में संग्रहित डेटा को बदलने और संभालने के लिए।
  • Commands: INSERT, UPDATE, DELETE, SELECT.
  1. DCL (Data Control Language):
  • डेटाबेस में access और permissions को नियंत्रित करने के लिए।
  • Commands: GRANT, REVOKE.
  1. TCL (Transaction Control Language):
  • डेटाबेस transactions को प्रबंधित करने के लिए।
  • Commands: COMMIT, ROLLBACK, SAVEPOINT.
  1. DQL (Data Query Language):
  • डेटाबेस से डेटा निकालने के लिए।
  • Command: SELECT.

Q. What are the Advantages and Disadvantages of Database System?

In English

Advantages:

  1. Reduces data redundancy and inconsistency.
  2. Provides data security and privacy.
  3. Easy data sharing among multiple users.
  4. Ensures data integrity and accuracy.
  5. Supports backup and recovery of data.
  6. Centralized management of data.
  7. Better performance in large organizations.

Disadvantages:

  1. High cost of hardware, software, and staff training.
  2. Complexity in design and management.
  3. Requires large memory and storage space.
  4. Risk of data loss if system crashes without backup.
  5. Unauthorized access may lead to data misuse.

हिन्दी में

फायदे:

  1. डेटा की पुनरावृत्ति और असंगति को कम करता है।
  2. डेटा की सुरक्षा और गोपनीयता प्रदान करता है।
  3. कई उपयोगकर्ताओं के बीच डेटा साझा करना आसान।
  4. डेटा की शुद्धता और अखंडता सुनिश्चित करता है।
  5. डेटा का बैकअप और रिकवरी सपोर्ट करता है।
  6. डेटा का केंद्रीकृत प्रबंधन।
  7. बड़ी संस्थाओं में बेहतर प्रदर्शन।

नुकसान:

  1. हार्डवेयर, सॉफ़्टवेयर और प्रशिक्षण की उच्च लागत।
  2. डिजाइन और प्रबंधन में जटिलता।
  3. अधिक मेमोरी और स्टोरेज की आवश्यकता।
  4. बैकअप न होने पर सिस्टम क्रैश से डेटा खो सकता है।
  5. अनधिकृत पहुँच से डेटा का दुरुपयोग हो सकता है।

Q. Explain NULL Value and Comment

In English

NULL Value:

  • NULL means the absence of a value in a table column.
  • It is not the same as zero or an empty string.
  • NULL indicates that the data is unknown, missing, or not applicable.
  • Example: If a student’s phone number is not given, it will be stored as NULL.

Comment:

  • Comments are used to explain SQL code but are ignored by the database during execution.
  • They make queries easy to understand for programmers.
  • Types of comments in SQL:
  • Single-line comment → -- This is a comment
  • Multi-line comment → /* This is a multi-line comment */

हिन्दी में

NULL Value:

  • NULL का मतलब है कि कॉलम में कोई मान मौजूद नहीं है।
  • यह शून्य (0) या खाली स्ट्रिंग (“”) के समान नहीं होता।
  • NULL दर्शाता है कि डेटा अज्ञात, अनुपलब्ध या लागू नहीं है।
  • उदाहरण: यदि छात्र का फ़ोन नंबर दर्ज नहीं है, तो उसे NULL रखा जाएगा।

Comment:

  • SQL कोड को समझाने के लिए कमेंट का प्रयोग किया जाता है।
  • डेटाबेस इन्हें execute नहीं करता, केवल प्रोग्रामर के लिए होते हैं।
  • SQL में कमेंट के प्रकार:
  • सिंगल लाइन कमेंट → -- यह एक कमेंट है
  • मल्टी लाइन कमेंट → /* यह मल्टी लाइन कमेंट है */

Q. What are Special Operators in SQL?

In English

Special operators in SQL are used to perform specific conditions in queries. Some important operators are:

  • BETWEEN → Used to check if a value lies within a given range.
  • Example: SELECT * FROM Students WHERE Age BETWEEN 18 AND 25;
  • IN → Used to match a value from a list of values.
  • Example: SELECT * FROM Employees WHERE Department IN ('HR','IT','Sales');
  • LIKE → Used for pattern matching with wildcards (%, _).
  • Example: SELECT * FROM Customers WHERE Name LIKE 'A%';
  • IS NULL → Used to check if a column has NULL value.
  • Example: SELECT * FROM Orders WHERE DeliveryDate IS NULL;
  • ANY/ALL → Used with subqueries to compare values.
  • Example: Salary > ANY (subquery) or Salary > ALL (subquery).
  • EXISTS → Used to check the existence of rows returned by a subquery.
  • Example: SELECT * FROM Products WHERE EXISTS (SELECT * FROM Orders WHERE Products.ID = Orders.ProductID);

हिन्दी में

SQL में विशेष ऑपरेटर (Special Operators) का उपयोग अलग-अलग शर्तें लगाने के लिए किया जाता है। मुख्य ऑपरेटर इस प्रकार हैं:

  • BETWEEN → किसी मान को एक रेंज के अंदर चेक करने के लिए।
  • उदाहरण: SELECT * FROM Students WHERE Age BETWEEN 18 AND 25;
  • IN → किसी मान को दिए गए मानों की सूची में चेक करने के लिए।
  • उदाहरण: SELECT * FROM Employees WHERE Department IN ('HR','IT','Sales');
  • LIKE → पैटर्न मिलाने के लिए (Wildcards %, _ का उपयोग)।
  • उदाहरण: SELECT * FROM Customers WHERE Name LIKE 'A%';
  • IS NULL → यह चेक करने के लिए कि कॉलम में NULL वैल्यू है या नहीं।
  • उदाहरण: SELECT * FROM Orders WHERE DeliveryDate IS NULL;
  • ANY/ALL → सबक्वेरी से प्राप्त मानों की तुलना करने के लिए।
  • उदाहरण: Salary > ANY (subquery) या Salary > ALL (subquery)
  • EXISTS → सबक्वेरी से पंक्तियों (rows) के अस्तित्व को चेक करने के लिए।
  • उदाहरण: SELECT * FROM Products WHERE EXISTS (SELECT * FROM Orders WHERE Products.ID = Orders.ProductID);

Q. Explain ORDER BY Clause with Syntax and Example

In English

The ORDER BY clause in SQL is used to sort the result of a query in ascending (ASC) or descending (DESC) order based on one or more columns.

Syntax:

SELECT column1, column2, ...
FROM table_name
ORDER BY column_name [ASC|DESC];

Example 1 (Ascending Order):

SELECT * FROM Students
ORDER BY Name ASC;

This will display all students sorted by their names in alphabetical order.

Example 2 (Descending Order):

SELECT * FROM Students
ORDER BY Marks DESC;

This will display all students sorted by their marks from highest to lowest.


हिन्दी में

SQL में ORDER BY क्लॉज़ का उपयोग क्वेरी के परिणाम को किसी कॉलम के आधार पर बढ़ते क्रम (ASC) या घटते क्रम (DESC) में व्यवस्थित करने के लिए किया जाता है।

सिंटैक्स:

SELECT column1, column2, ...
FROM table_name
ORDER BY column_name [ASC|DESC];

उदाहरण 1 (बढ़ते क्रम में):

SELECT * FROM Students
ORDER BY Name ASC;

यह सभी छात्रों को नाम के आधार पर वर्णक्रम (A से Z) में दिखाएगा।

उदाहरण 2 (घटते क्रम में):

SELECT * FROM Students
ORDER BY Marks DESC;

यह सभी छात्रों को अंकों के आधार पर उच्च से निम्न क्रम में दिखाएगा।

Q. What are Comparison or Relational Operators of SQL?

In English

Comparison or Relational operators in SQL are used to compare two values. The result of comparison is either TRUE or FALSE.

Operators:

  • = → Equal to
  • Example: SELECT * FROM Students WHERE Age = 18;
  • <> or != → Not equal to
  • Example: SELECT * FROM Students WHERE Age <> 18;
  • > → Greater than
  • Example: SELECT * FROM Students WHERE Marks > 50;
  • < → Less than
  • Example: SELECT * FROM Students WHERE Marks < 50;
  • >= → Greater than or equal to
  • Example: SELECT * FROM Students WHERE Marks >= 40;
  • <= → Less than or equal to
  • Example: SELECT * FROM Students WHERE Marks <= 40;

हिन्दी में

SQL में Comparison या Relational Operators का उपयोग दो मानों की तुलना करने के लिए किया जाता है। तुलना का परिणाम TRUE या FALSE होता है।

ऑपरेटर:

  • = → बराबर
  • उदाहरण: SELECT * FROM Students WHERE Age = 18;
  • <> या != → बराबर नहीं
  • उदाहरण: SELECT * FROM Students WHERE Age <> 18;
  • > → से बड़ा
  • उदाहरण: SELECT * FROM Students WHERE Marks > 50;
  • < → से छोटा
  • उदाहरण: SELECT * FROM Students WHERE Marks < 50;
  • >= → बड़ा या बराबर
  • उदाहरण: SELECT * FROM Students WHERE Marks >= 40;
  • <= → छोटा या बराबर
  • उदाहरण: SELECT * FROM Students WHERE Marks <= 40;

Q. What is DDL Language? Different Commands of DDL

In English

DDL stands for Data Definition Language. It is used to define and manage the structure of a database, such as creating, altering, and deleting database objects like tables, indexes, and views. DDL commands automatically commit changes, meaning they are permanent.

Different DDL Commands:

  • CREATE → Used to create database objects like tables, views, or databases.
  • Example: CREATE TABLE Students (ID INT, Name VARCHAR(50));
  • ALTER → Used to modify the structure of an existing table.
  • Example: ALTER TABLE Students ADD Age INT;
  • DROP → Used to delete database objects permanently.
  • Example: DROP TABLE Students;
  • TRUNCATE → Used to remove all rows from a table but keeps the structure.
  • Example: TRUNCATE TABLE Students;
  • RENAME → Used to rename database objects.
  • Example: RENAME TABLE Students TO Learners;

हिन्दी में

DDL का पूरा नाम है Data Definition Language। इसका उपयोग डेटाबेस की संरचना (Structure) को परिभाषित और प्रबंधित करने के लिए किया जाता है। इसमें टेबल, इंडेक्स, व्यू आदि को बनाना, बदलना और हटाना शामिल है। DDL कमांड अपने आप commit हो जाते हैं, यानी बदलाव स्थायी होते हैं।

DDL कमांड्स:

  • CREATE → डेटाबेस ऑब्जेक्ट जैसे टेबल, व्यू या डेटाबेस बनाने के लिए।
  • उदाहरण: CREATE TABLE Students (ID INT, Name VARCHAR(50));
  • ALTER → किसी मौजूदा टेबल की संरचना बदलने के लिए।
  • उदाहरण: ALTER TABLE Students ADD Age INT;
  • DROP → डेटाबेस ऑब्जेक्ट को स्थायी रूप से हटाने के लिए।
  • उदाहरण: DROP TABLE Students;
  • TRUNCATE → टेबल से सभी पंक्तियाँ हटाने के लिए, लेकिन संरचना बनी रहती है।
  • उदाहरण: TRUNCATE TABLE Students;
  • RENAME → डेटाबेस ऑब्जेक्ट का नाम बदलने के लिए।
  • उदाहरण: RENAME TABLE Students TO Learners;

Q. What is CREATE and ALTER Command?

In English

CREATE Command:
The CREATE command in SQL is used to create new database objects such as databases, tables, views, or indexes.

Example:

CREATE TABLE Students (
   ID INT,
   Name VARCHAR(50),
   Age INT
);

This command creates a table named Students with three columns: ID, Name, and Age.

ALTER Command:
The ALTER command is used to modify the structure of an existing table. With ALTER we can add, delete, or modify columns.

Examples:

ALTER TABLE Students ADD Marks INT;

(Adds a new column “Marks”)

ALTER TABLE Students MODIFY Name VARCHAR(100);

(Changes the size of column “Name”)


हिन्दी में

CREATE Command:
SQL में CREATE कमांड का उपयोग नए डेटाबेस ऑब्जेक्ट जैसे डेटाबेस, टेबल, व्यू या इंडेक्स बनाने के लिए किया जाता है।

उदाहरण:

CREATE TABLE Students (
   ID INT,
   Name VARCHAR(50),
   Age INT
);

यह कमांड Students नाम की टेबल बनाता है जिसमें तीन कॉलम हैं: ID, Name और Age।

ALTER Command:
ALTER कमांड का उपयोग किसी मौजूदा टेबल की संरचना बदलने के लिए किया जाता है। इसके द्वारा कॉलम जोड़ सकते हैं, हटा सकते हैं या बदल सकते हैं।

उदाहरण:

ALTER TABLE Students ADD Marks INT;

(नया कॉलम “Marks” जोड़ता है)

ALTER TABLE Students MODIFY Name VARCHAR(100);

(“Name” कॉलम का साइज़ बदलता है)

Q. 1. Explain GROUP BY Clause

In English

The GROUP BY clause in SQL is used to arrange identical data into groups. It is often used with aggregate functions like COUNT, SUM, AVG, MAX, MIN to perform calculations on each group of data.

Syntax:

SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;

Example:

SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department;

This query will count the number of employees in each department.


हिन्दी में

SQL में GROUP BY क्लॉज़ का उपयोग समान प्रकार के डेटा को समूहों (Groups) में व्यवस्थित करने के लिए किया जाता है। इसे अधिकतर COUNT, SUM, AVG, MAX, MIN जैसे aggregate functions के साथ उपयोग किया जाता है।

सिंटैक्स:

SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;

उदाहरण:

SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department;

यह क्वेरी प्रत्येक विभाग (Department) में कर्मचारियों की संख्या बताएगी।


Q. 2. Explain RDBMS with Example

In English

RDBMS stands for Relational Database Management System. It stores data in the form of tables (rows and columns) and allows relationships between them. It supports SQL for managing and retrieving data. Common examples are MySQL, Oracle, SQL Server.

Example:
If we have two tables:

Students Table

StudentIDNameClass
1John10
2Rita12

Marks Table

StudentIDSubjectMarks
1Maths90
2Science85

Here, StudentID acts as a relation (foreign key) connecting Students and Marks tables.


हिन्दी में

RDBMS का पूरा नाम है Relational Database Management System। इसमें डेटा को टेबल (rows और columns) के रूप में संग्रहित किया जाता है और अलग-अलग टेबल्स के बीच संबंध बनाए जाते हैं। इसमें डेटा को प्रबंधित और प्राप्त करने के लिए SQL का उपयोग होता है। सामान्य उदाहरण: MySQL, Oracle, SQL Server

उदाहरण:
मान लीजिए हमारे पास दो टेबल हैं:

Students Table

StudentIDNameClass
1John10
2Rita12

Marks Table

StudentIDSubjectMarks
1Maths90
2Science85

यहाँ StudentID दोनों टेबल्स को जोड़ने का काम करता है (foreign key)।

Q. What do you mean by HAVING Clause?

In English

The HAVING clause in SQL is used to apply conditions on groups created by the GROUP BY clause. Since the WHERE clause cannot be used with aggregate functions, HAVING is used to filter grouped data.

Syntax:

SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;

Example:

SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 5;

This query shows only those departments which have more than 5 employees.


हिन्दी में

SQL में HAVING क्लॉज़ का उपयोग GROUP BY क्लॉज़ से बने समूहों पर शर्त लगाने के लिए किया जाता है। चूंकि WHERE क्लॉज़ को aggregate functions के साथ उपयोग नहीं किया जा सकता, इसलिए HAVING का प्रयोग किया जाता है।

सिंटैक्स:

SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;

उदाहरण:

SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 5;

यह क्वेरी केवल उन्हीं विभागों को दिखाएगी जिनमें 5 से अधिक कर्मचारी हैं।

Q. What is Group Function? What are various Group Functions?

In English

Group Functions (also called Aggregate Functions) in SQL are functions that perform a calculation on a set of values and return a single value.
They are mostly used with the GROUP BY clause.

Common Group Functions in SQL:

  1. COUNT() → Returns number of rows.
   SELECT COUNT(*) FROM Employees;
  1. SUM() → Returns total of numeric column.
   SELECT SUM(Salary) FROM Employees;
  1. AVG() → Returns average of numeric column.
   SELECT AVG(Salary) FROM Employees;
  1. MAX() → Returns highest value.
   SELECT MAX(Salary) FROM Employees;
  1. MIN() → Returns lowest value.
   SELECT MIN(Salary) FROM Employees;

हिन्दी में

Group Functions (जिन्हें Aggregate Functions भी कहते हैं) SQL में ऐसे functions होते हैं जो एक set of values पर calculation करके एक single value return करते हैं।
ये functions ज़्यादातर GROUP BY क्लॉज़ के साथ प्रयोग होते हैं।

मुख्य Group Functions:

  1. COUNT() → पंक्तियों की संख्या बताता है।
   SELECT COUNT(*) FROM Employees;
  1. SUM() → संख्यात्मक कॉलम का योग (total) देता है।
   SELECT SUM(Salary) FROM Employees;
  1. AVG() → औसत (average) बताता है।
   SELECT AVG(Salary) FROM Employees;
  1. MAX() → सबसे बड़ी (highest) value देता है।
   SELECT MAX(Salary) FROM Employees;
  1. MIN() → सबसे छोटी (lowest) value देता है।
   SELECT MIN(Salary) FROM Employees;

👉 Do you want me to also prepare this in a short exam-note table format (Functions + Description + Example) for quick revision?

Q. What is Group Function? What are various Group Functions?

In English

Group Functions (also called Aggregate Functions) in SQL are functions that perform a calculation on a set of values and return a single value.
They are mostly used with the GROUP BY clause.

Common Group Functions in SQL:

  1. COUNT() → Returns number of rows.
   SELECT COUNT(*) FROM Employees;
  1. SUM() → Returns total of numeric column.
   SELECT SUM(Salary) FROM Employees;
  1. AVG() → Returns average of numeric column.
   SELECT AVG(Salary) FROM Employees;
  1. MAX() → Returns highest value.
   SELECT MAX(Salary) FROM Employees;
  1. MIN() → Returns lowest value.
   SELECT MIN(Salary) FROM Employees;

हिन्दी में

Group Functions (जिन्हें Aggregate Functions भी कहते हैं) SQL में ऐसे functions होते हैं जो एक set of values पर calculation करके एक single value return करते हैं।
ये functions ज़्यादातर GROUP BY क्लॉज़ के साथ प्रयोग होते हैं।

मुख्य Group Functions:

  1. COUNT() → पंक्तियों की संख्या बताता है।
   SELECT COUNT(*) FROM Employees;
  1. SUM() → संख्यात्मक कॉलम का योग (total) देता है।
   SELECT SUM(Salary) FROM Employees;
  1. AVG() → औसत (average) बताता है।
   SELECT AVG(Salary) FROM Employees;
  1. MAX() → सबसे बड़ी (highest) value देता है।
   SELECT MAX(Salary) FROM Employees;
  1. MIN() → सबसे छोटी (lowest) value देता है।
   SELECT MIN(Salary) FROM Employees;

In English

String Functions in SQL are functions that are used to perform operations on string data types like CHAR and VARCHAR. These functions help in manipulating, modifying, and retrieving string values.

Common String Functions:

  1. CONCAT() → Joins two or more strings.
   SELECT CONCAT('Hello',' World');
  1. LENGTH() → Returns length of a string.
   SELECT LENGTH('SQL');
  1. LOWER() / LCASE() → Converts string to lowercase.
   SELECT LOWER('HELLO');
  1. UPPER() / UCASE() → Converts string to uppercase.
   SELECT UPPER('hello');
  1. SUBSTRING() / MID() → Extracts part of a string.
   SELECT SUBSTRING('Database',2,4);
  1. TRIM() → Removes leading and trailing spaces.
   SELECT TRIM('   SQL   ');
  1. REPLACE() → Replaces occurrences of a substring.
   SELECT REPLACE('Good Morning','Morning','Evening');

हिन्दी में

String Functions SQL में वे functions हैं जिनका प्रयोग CHAR और VARCHAR जैसे string data types पर operations करने के लिए किया जाता है। इनका उपयोग string को बदलने, जोड़ने और निकालने में होता है।

मुख्य String Functions:

  1. CONCAT() → दो या अधिक strings को जोड़ता है।
   SELECT CONCAT('Hello',' World');
  1. LENGTH() → string की लंबाई बताता है।
   SELECT LENGTH('SQL');
  1. LOWER() / LCASE() → string को छोटे अक्षरों (lowercase) में बदलता है।
   SELECT LOWER('HELLO');
  1. UPPER() / UCASE() → string को बड़े अक्षरों (uppercase) में बदलता है।
   SELECT UPPER('hello');
  1. SUBSTRING() / MID() → string का कुछ हिस्सा निकालता है।
   SELECT SUBSTRING('Database',2,4);
  1. TRIM() → आगे और पीछे के spaces हटाता है।
   SELECT TRIM('   SQL   ');
  1. REPLACE() → string के अंदर किसी शब्द को बदलता है।
   SELECT REPLACE('Good Morning','Morning','Evening');

In English

Comments in SQL are used to add explanations or notes within SQL code. They are ignored by the SQL engine during execution. Comments make queries easier to understand.

Types of Comments in SQL:

  1. Single-line Comment → Starts with --
   -- This is a single-line comment
   SELECT * FROM Students;
  1. Multi-line Comment → Written between /* ... */
   /* This is a
      multi-line comment */
   SELECT * FROM Teachers;

हिन्दी में

SQL में Comments का प्रयोग SQL code के अंदर explanation या note लिखने के लिए किया जाता है। SQL engine इनको execute नहीं करता। ये सिर्फ query को समझने में मदद करते हैं।

SQL में Comments के प्रकार:

  1. Single-line Comment-- से शुरू होता है
   -- यह single-line comment है
   SELECT * FROM Students;
  1. Multi-line Comment/* ... */ के बीच लिखा जाता है
   /* यह multi-line
      comment है */
   SELECT * FROM Teachers;

Q. What is Key? What are Various Kinds of Keys?

In English

Key in SQL/DBMS is a field or set of fields used to uniquely identify records in a table and to create relationships between tables. Keys ensure data integrity and help in retrieving data efficiently.

Kinds of Keys:

  1. Primary Key → Uniquely identifies each record in a table.
  2. Candidate Key → All possible attributes that can be a primary key.
  3. Super Key → A set of one or more attributes that can uniquely identify a record.
  4. Foreign Key → A key used to link two tables, refers to the primary key of another table.
  5. Composite Key → A key formed by combining two or more attributes to uniquely identify records.
  6. Alternate Key → Candidate keys that are not selected as the primary key.
  7. Unique Key → Ensures all values in a column are unique but allows one null value.

हिन्दी में

Key SQL/DBMS में वह field या fields का समूह है जो किसी टेबल में रिकॉर्ड को uniquely पहचानने और टेबल्स के बीच संबंध बनाने के लिए उपयोग होता है। Keys डेटा की शुद्धता (integrity) और retrieval को आसान बनाती हैं।

Keys के प्रकार:

  1. Primary Key → हर रिकॉर्ड को uniquely पहचानता है।
  2. Candidate Key → वे सभी attributes जो primary key हो सकते हैं।
  3. Super Key → एक या अधिक attributes का समूह जो रिकॉर्ड को uniquely पहचान सकता है।
  4. Foreign Key → दो टेबल को जोड़ने के लिए, यह दूसरी टेबल की primary key को refer करता है।
  5. Composite Key → दो या अधिक attributes को मिलाकर बनाया गया key।
  6. Alternate Key → Candidate keys जो primary key के रूप में चुने नहीं गए।
  7. Unique Key → सभी values को unique रखता है, पर एक null value allow करता है।

Q. What is Key? What are Various Kinds of Keys with Example?

In English

Key in SQL/DBMS is a field or set of fields used to uniquely identify records in a table and to create relationships between tables.

Suppose we have a table:

STUDENT

RollNoNameEmailClassDeptID
101Amanaman@gmail.com12th AD01
102Riyariya@gmail.com12th BD02
103Karankaran@gmail.com12th AD01

Kinds of Keys:

  1. Primary KeyRollNo (each student has a unique roll number).
  2. Candidate KeyRollNo, Email (both can uniquely identify a record).
  3. Super Key{RollNo, Name}, {Email}, etc. (any attribute set that uniquely identifies record).
  4. Foreign KeyDeptID (refers to DeptID in another table called DEPARTMENT).
  5. Composite Key(RollNo, Class) (combination to identify uniquely in special cases).
  6. Alternate Key → If RollNo is chosen as Primary Key, then Email becomes an Alternate Key.
  7. Unique KeyEmail (all emails must be unique, but one null value is allowed).

हिन्दी में

Key SQL/DBMS में वह field या fields का समूह है जो किसी टेबल में रिकॉर्ड को uniquely पहचानने और टेबल्स के बीच संबंध बनाने के लिए उपयोग होता है।

मान लीजिए हमारे पास एक टेबल है:

STUDENT

RollNoNameEmailClassDeptID
101Amanaman@gmail.com12th AD01
102Riyariya@gmail.com12th BD02
103Karankaran@gmail.com12th AD01

Keys के प्रकार:

  1. Primary KeyRollNo (हर छात्र का यूनिक रोल नंबर होता है)।
  2. Candidate KeyRollNo, Email (दोनों uniquely पहचान सकते हैं)।
  3. Super Key{RollNo, Name}, {Email} आदि (ऐसा कोई भी attribute set जो uniquely पहचान सके)।
  4. Foreign KeyDeptID (दूसरी टेबल DEPARTMENT की primary key को refer करता है)।
  5. Composite Key(RollNo, Class) (कभी-कभी combination से पहचानना पड़ता है)।
  6. Alternate Key → अगर RollNo को Primary Key चुन लिया जाए तो Email Alternate Key होगी।
  7. Unique KeyEmail (हर ईमेल unique होगा, लेकिन एक null value allow होती है)।

Q. What is Relational and Logical Operator?

In English

Relational Operators are used to compare two values in SQL. They return TRUE or FALSE based on the condition.

Examples:

  • = : Equal to
  • != or <> : Not equal to
  • > : Greater than
  • < : Less than
  • >= : Greater than or equal to
  • <= : Less than or equal to

Example Query:

SELECT * FROM Student WHERE Marks > 50;

(This shows all students who have marks greater than 50).


Logical Operators are used to combine multiple conditions in SQL.

Examples:

  • AND : Returns TRUE if all conditions are true.
  • OR : Returns TRUE if any one condition is true.
  • NOT : Reverses the result of a condition.

Example Query:

SELECT * FROM Student WHERE Marks > 50 AND Class = '12th A';

(Shows students with marks greater than 50 and in class 12th A).


हिन्दी में

Relational Operators SQL में दो values की तुलना करने के लिए उपयोग होते हैं। ये TRUE या FALSE परिणाम देते हैं।

उदाहरण:

  • = : बराबर
  • != या <> : बराबर नहीं
  • > : बड़ा
  • < : छोटा
  • >= : बड़ा या बराबर
  • <= : छोटा या बराबर

उदाहरण Query:

SELECT * FROM Student WHERE Marks > 50;

(सभी छात्रों को दिखाएगा जिनके अंक 50 से ज्यादा हैं)।


Logical Operators SQL में conditions को जोड़ने के लिए उपयोग होते हैं।

उदाहरण:

  • AND : TRUE जब सारी conditions सही हों।
  • OR : TRUE जब कोई एक condition सही हो।
  • NOT : किसी condition का उल्टा परिणाम देता है।

उदाहरण Query:

SELECT * FROM Student WHERE Marks > 50 AND Class = '12th A';

(वे छात्र दिखाएगा जिनके अंक 50 से ज्यादा हैं और जो 12th A में हैं)।


Q. What is Special Operator used with WHERE Clause like BETWEEN, IN, LIKE, IS NULL?

In English

Special operators in SQL are used with the WHERE clause to filter records based on specific conditions.

1. BETWEEN Operator

  • Used to select values within a given range.
SELECT * FROM Student WHERE Marks BETWEEN 50 AND 80;

(Shows students with marks from 50 to 80).

2. IN Operator

  • Used to match values from a list.
SELECT * FROM Student WHERE Class IN ('10th', '12th');

(Shows students from class 10th or 12th).

3. LIKE Operator

  • Used for pattern matching with wildcards (% and _).
SELECT * FROM Student WHERE Name LIKE 'A%';

(Shows all students whose name starts with A).

4. IS NULL Operator

  • Used to check for NULL (missing) values.
SELECT * FROM Student WHERE Address IS NULL;

(Shows students who don’t have address data).


हिन्दी में

SQL में Special operators का उपयोग WHERE clause के साथ records को विशेष conditions पर filter करने के लिए किया जाता है।

1. BETWEEN Operator

  • किसी दिए गए range के बीच values चुनने के लिए।
SELECT * FROM Student WHERE Marks BETWEEN 50 AND 80;

(वे छात्र दिखाएगा जिनके अंक 50 से 80 के बीच हैं)।

2. IN Operator

  • किसी list से values चुनने के लिए।
SELECT * FROM Student WHERE Class IN ('10th', '12th');

(वे छात्र दिखाएगा जो 10th या 12th कक्षा में हैं)।

3. LIKE Operator

  • Pattern matching के लिए (% और _ के साथ)।
SELECT * FROM Student WHERE Name LIKE 'A%';

(वे छात्र दिखाएगा जिनका नाम A से शुरू होता है)।

4. IS NULL Operator

  • NULL (missing) values को check करने के लिए।
SELECT * FROM Student WHERE Address IS NULL;

(वे छात्र दिखाएगा जिनका address भरा नहीं गया है)।


Q. What is Special Operator used with WHERE Clause like BETWEEN, IN, LIKE, IS NULL?

In English

Special operators in SQL are used with the WHERE clause to filter records based on specific conditions.

OperatorPurposeExampleResult
BETWEENSelects values within a rangeSELECT * FROM Student WHERE Marks BETWEEN 50 AND 80;Students with marks between 50 and 80
INMatches values from a listSELECT * FROM Student WHERE Class IN ('10th','12th');Students of class 10th or 12th
LIKEUsed for pattern matchingSELECT * FROM Student WHERE Name LIKE 'A%';Students whose name starts with A
IS NULLChecks for NULL valuesSELECT * FROM Student WHERE Address IS NULL;Students without address data

हिन्दी में

SQL में Special operators का उपयोग WHERE clause के साथ records को विशेष conditions पर filter करने के लिए किया जाता है।

ऑपरेटरउपयोगउदाहरणपरिणाम
BETWEENदिए गए range के बीच values चुनने के लिएSELECT * FROM Student WHERE Marks BETWEEN 50 AND 80;50 से 80 अंकों वाले छात्र
INकिसी list से values चुनने के लिएSELECT * FROM Student WHERE Class IN ('10th','12th');10th या 12th कक्षा के छात्र
LIKEPattern matching के लिएSELECT * FROM Student WHERE Name LIKE 'A%';जिन छात्रों का नाम A से शुरू होता है
IS NULLNULL values check करने के लिएSELECT * FROM Student WHERE Address IS NULL;जिन छात्रों का address नहीं है

Q. What do you mean by Key? Explain in detail Primary Key, Candidate Key, Super Key, Alternate Key, and Foreign Key.

In English

Key: A key in DBMS is an attribute (or set of attributes) used to identify a row (record) uniquely in a table. Keys are also used to establish and identify relationships between tables.

1. Primary Key (PK):

  • A column (or set of columns) that uniquely identifies each record in a table.
  • It cannot have NULL values.
  • Each table can have only one primary key.
  • Example: In a Student table, Roll_No can be a primary key.

2. Candidate Key (CK):

  • All attributes which can uniquely identify a record are candidate keys.
  • From these, one is chosen as the primary key.
  • Example: In Student table, both Roll_No and Email can uniquely identify a record. Both are candidate keys.

3. Super Key (SK):

  • A set of one or more attributes that can uniquely identify a record.
  • It may contain extra attributes apart from candidate key.
  • Example: {Roll_No}, {Roll_No, Name}, {Email, Phone_No}.

4. Alternate Key (AK):

  • Candidate keys that are not chosen as the primary key are called alternate keys.
  • Example: If Roll_No is chosen as primary key, then Email becomes alternate key.

5. Foreign Key (FK):

  • A column (or set of columns) in one table that refers to the primary key in another table.
  • It is used to maintain referential integrity.
  • Example: In an “Orders” table, Customer_ID is foreign key which refers to Customer_ID in “Customers” table.

हिन्दी में

Key (कुंजी): DBMS में कुंजी ऐसे गुण (attributes) होते हैं जो किसी तालिका (table) की पंक्ति (row/record) को uniquely पहचानने के लिए उपयोग किए जाते हैं। Keys का प्रयोग तालिकाओं के बीच संबंध बनाने और पहचानने के लिए भी होता है।

1. Primary Key (प्राथमिक कुंजी):

  • यह कॉलम (या कॉलम्स का समूह) होता है जो प्रत्येक रिकॉर्ड को uniquely पहचानता है।
  • इसमें NULL मान (value) नहीं हो सकता।
  • एक तालिका में केवल एक Primary Key हो सकती है।
  • उदाहरण: Student तालिका में Roll_No Primary Key हो सकता है।

2. Candidate Key (उम्मीदवार कुंजी):

  • सभी attributes जो uniquely किसी रिकॉर्ड को पहचान सकते हैं, candidate key कहलाते हैं।
  • इन्हीं में से एक को primary key चुना जाता है।
  • उदाहरण: Student तालिका में Roll_No और Email, दोनों uniquely पहचान सकते हैं।

3. Super Key (सुपर कुंजी):

  • एक या एक से अधिक attributes का समूह जो uniquely रिकॉर्ड को पहचान सकता है।
  • इसमें अतिरिक्त attributes भी हो सकते हैं।
  • उदाहरण: {Roll_No}, {Roll_No, Name}, {Email, Phone_No}।

4. Alternate Key (वैकल्पिक कुंजी):

  • Candidate keys में से जो primary key के रूप में नहीं चुनी जाती, वह Alternate Key कहलाती है।
  • उदाहरण: अगर Roll_No को primary key चुना गया है, तो Email alternate key होगी।

5. Foreign Key (विदेशी कुंजी):

  • यह एक तालिका का कॉलम होता है जो दूसरी तालिका की Primary Key को संदर्भित करता है।
  • इसका उपयोग Referential Integrity बनाए रखने के लिए किया जाता है।
  • उदाहरण: “Orders” तालिका में Customer_ID, “Customers” तालिका की Customer_ID को संदर्भित करता है।

(table form)


In English

Key TypeDefinitionExample
Primary Key (PK)Uniquely identifies each record in a table. Cannot be NULL. Only one per table.In Student table, Roll_No as PK.
Candidate Key (CK)All possible attributes that can uniquely identify a record. One of them is chosen as PK.Roll_No, Email.
Super Key (SK)A set of attributes that can uniquely identify a record (may include extra attributes).{Roll_No}, {Roll_No, Name}.
Alternate Key (AK)Candidate keys which are not selected as Primary Key.If Roll_No is PK, then Email is AK.
Foreign Key (FK)A key that refers to the Primary Key in another table. Maintains referential integrity.In “Orders” table, Customer_ID refers to “Customers” table Customer_ID.

हिन्दी में

कुंजी का प्रकारपरिभाषाउदाहरण
Primary Key (PK)प्रत्येक रिकॉर्ड को uniquely पहचानता है। NULL नहीं हो सकता। एक ही Primary Key होती है।Student तालिका में Roll_No
Candidate Key (CK)सभी attributes जो uniquely पहचान सकते हैं। इन्हीं में से एक PK चुना जाता है।Roll_No, Email
Super Key (SK)एक या अधिक attributes का समूह जो uniquely पहचान सकता है। इसमें अतिरिक्त attributes भी हो सकते हैं।{Roll_No}, {Roll_No, Name}।
Alternate Key (AK)Candidate Keys जो Primary Key के रूप में नहीं चुनी जातीं।अगर Roll_No PK है, तो Email AK होगी।
Foreign Key (FK)यह दूसरी तालिका की Primary Key को संदर्भित करता है। Referential Integrity बनाए रखता है।“Orders” तालिका में Customer_ID, “Customers” तालिका की Customer_ID को संदर्भित करता है।

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *