0% found this document useful (0 votes)
4 views6 pages

SQL Commands and Functions Explained

The document outlines SQL commands categorized into Data Definition Language (DDL) and Data Manipulation Language (DML), detailing their purposes and examples. It covers various SQL functions, grouping, and join queries, as well as differences between related SQL concepts. Additionally, it defines key database terms and concepts essential for understanding relational databases.

Uploaded by

ajay12346ajay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

SQL Commands and Functions Explained

The document outlines SQL commands categorized into Data Definition Language (DDL) and Data Manipulation Language (DML), detailing their purposes and examples. It covers various SQL functions, grouping, and join queries, as well as differences between related SQL concepts. Additionally, it defines key database terms and concepts essential for understanding relational databases.

Uploaded by

ajay12346ajay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​DROP DATABASE SchoolDB;​

​1. Data Definition Language (DDL) Commands​


​DESCRIBE/DESC​ ​ sed to display the structure of a table (column names, data​
U
​These commands are used to​​define​​or modify the structure​​of the database objects.​
​types, constraints).​

​Command​ ​Purpose & Example​

​DESC Student;​

​CREATE​ ​Used to create a new database or table.​

​2. Data Manipulation Language (DML) Commands​


​CREATE DATABASE SchoolDB;​
​These commands are used to​​manipulate​​the data stored​​in the database tables.​

​Command​ ​Purpose & Example​


​ REATE TABLE Student (RollNo INT PRIMARY KEY, Name​
C
​VARCHAR(50), Class CHAR(3));​

​INSERT INTO​ ​Used to add new rows/records to a table.​

​ALTER​ ​Used to modify the structure of an existing table.​

I​NSERT INTO Student (RollNo, Name, Class) VALUES (1, 'Alia',​


​'XIIA');​
​ dd a column:​​ALTER TABLE Student ADD COLUMN City​
A
​VARCHAR(30);​

​SELECT​ ​ sed to retrieve data from a table. This is the most frequently used​
U
​command and involves numerous clauses:​
​ odify a column's data type:​​ALTER TABLE Student MODIFY​
M
​COLUMN Name VARCHAR(100);​

​Retrieve all data:​​SELECT * FROM Student;​

​Drop a column:​​ALTER TABLE Student DROP COLUMN City;​

​Retrieve specific columns:​​SELECT Name, Class FROM​​Student;​

​DROP​ ​ sed to delete an entire table or database. (Irreversible:​


U
​removes both structure and data).​
​ ith​​WHERE​​clause (for filtering rows):​​SELECT * FROM​​Student​
W
​WHERE Class = 'XIIA' AND RollNo > 5;​

​DROP TABLE Student;​


​ ith​​ORDER BY​​clause (for sorting):​​SELECT Name, Marks​​FROM​
W ​SUM()​ ​ alculates the sum of values in a numeric​
C
​Student ORDER BY Marks DESC;​ ​column.​​SELECT SUM(Fees) FROM Student;​

​ ith​​DISTINCT​​clause (to remove duplicates):​​SELECT​​DISTINCT​


W ​AVG()​ ​ alculates the average value of a numeric​
C
​Class FROM Student;​ ​column.​​SELECT AVG(Marks) FROM Student;​

​ sing comparison operators:​​=​,​​>​,​​<​,​​!=​​or​​<>​​,​​>=​​,​​<=​​,​​BETWEEN​​,​


U ​MAX() / MIN()​ ​ inds the maximum/minimum value in a​
F
​LIKE​​,​​IN​​,​​IS NULL​​.​ ​column.​​SELECT MAX(Marks) FROM Student;​

​UPDATE​ ​ sed to modify existing data in a table.​​WHERE​​clause​​is essential​


U ​Grouping​ ​GROUP BY​ ​ roups rows with the same values for​
G
​to specify which rows to update.​ ​aggregate calculations.​​SELECT Class,​
​COUNT(*) FROM Student GROUP BY Class;​

​UPDATE Student SET Class = 'XIIB' WHERE Name = 'Alia';​


​HAVING​ ​ ilters the results of a​​GROUP BY​​clause​
F
​(similar to WHERE, but for groups).​​SELECT​
​Class, AVG(Marks) FROM Student GROUP BY​
​ ELETE​
D ​ sed to remove rows/records from a table.​​WHERE​​clause​​is​
U
​Class HAVING AVG(Marks) > 80;​
​FROM​ ​essential to specify which rows to delete.​

​DELETE FROM Student WHERE Marks < 33;​ ​4. JOIN Queries​
​ oins are used to combine rows from two or more tables based on a related column between​
J
​them.​
​ elete all rows:​​DELETE FROM Student;​​(Keeps the table​
D
​structure).​
​Type​ ​Purpose & Example (Using two tables:​​Student​​and​​Activity​​)​

​3. Functions and Grouping​ ​Equi-Join​ ​ ombines records from tables where the values in the specified​
C
​columns are equal (using the​​=​​operator in the​​WHERE​​clause).​
​These are critical for performing calculations and summarizing data.​

​Type​ ​Function/Clause​ ​Purpose & Example​


​ ELECT [Link], [Link] FROM Student S, Activity A​
S
​WHERE [Link] = [Link];​

​Aggregate​ ​COUNT()​ ​ ounts the number of rows/values.​​SELECT​


C
​COUNT(*) FROM Student WHERE Class =​
​'XIIA';​
​ atural​
N J​ oins tables automatically based on all columns with the same name​ ​CHAR​ ​VARCHAR​
​Join​ ​and data type, and the common column appears only once in the​
​result.​

​ . Length​
1 ​Fixed-length​​string data type.​ ​Variable-length​​string data type.​
​Type​
​ ELECT * FROM Student NATURAL JOIN Activity;​​(Less​​common in​
S
​board questions than Equi-Join).​

​ . Storage​
2 ​Allocates the​​maximum​ ​ llocates space based on the​
A
​Allocation​ ​actual data length​​plus 1 or 2​
​bytes for length information.​
​Here are 5 points of difference for each of the SQL pairs you listed:​
​ pecified size​​(​
s
​bytes), regardless of the​
​1. HAVING vs. WHERE​ ​actual data length.​

​HAVING Clause​ ​WHERE Clause​

​ . Space​
3 ​ ess space-efficient; wastes​
L ​ ore space-efficient; uses only​
M
​Usage​ ​space by​​padding​​shorter​ ​the space needed for the data.​
​ . Primary​
1 ​Filters​​groups​​of rows.​ ​Filters​​individual rows​​.​ ​strings with trailing spaces.​
​Purpose​

​ . Padding​
4 ​ ads​​shorter strings with​
P ​ oes not pad​​; stores the string​
D
​ . Aggregation​
2 ​ an​​use aggregate​
C ​ annot​​use aggregate​
C ​Behavior​ ​trailing spaces to meet the​ ​as-is.​
​Use​ ​functions (e.g.,​​SUM()​​,​ ​functions.​ ​fixed length.​
​COUNT()​​).​

​ . Best Use​
5 ​ or data with​​consistent,​
F ​ or data with​​varying lengths​
F
​ . Execution​
3 ​ pplied​​after​​the​​GROUP​
A ​ pplied​​before​​the​​GROUP​
A ​Case​ ​fixed lengths​​(e.g., state​ ​(e.g., names, addresses,​
​Order​ ​BY​​clause.​ ​BY​​clause.​ ​codes, 'Y'/'N' flags).​ ​descriptions).​

​4. Requirement​ ​ equires​​the use of the​


R I​s​​optional​​and works without​
​GROUP BY​​clause (to filter​ ​GROUP BY​​.​ ​3. DROP vs. DELETE​
​groups).​
​DROP Command​ ​DELETE Command​

​ . Applicable​
5 ​ nly used with the​​SELECT​
O ​ an be used with​​SELECT​​,​
C
​Statements​ ​statement.​ ​UPDATE​​, and​​DELETE​ ​ . SQL Command​
1 ​ DL​​(Data Definition​
D ​ ML​​(Data Manipulation​
D
​statements.​ ​Type​ ​Language).​ ​Language).​

​2. CHAR vs. VARCHAR​


​2. Target​ ​ emoves an entire​​database​
R ​ emoves​​rows​​(records)​
R ​ . Column​
4 ​ he common columns​​do not​
T ​ he common columns​​must​
T
​object​​(e.g., the table, index,​ ​from a table.​ ​Specification​ ​need​​to be specified in the join​ ​be specified​​in the join​
​view).​ ​clause.​ ​condition.​

​ . Structure​
3 ​ emoves the​​entire structure​
R ​ reserves the structure​
P ​5. Basis of Join​ ​ ased on column​​name​​and​
B ​ ased purely on​​value​
B
​Impact​ ​(schema, data, indexes).​ ​of the table.​ ​data type​​equality.​ ​equality​​of the specified​
​columns.​

​4. Reversibility​ I​rreversible​​(cannot be rolled​ ​ eversible​​(can be rolled​


R
​back) and is typically​ ​back) if used within a​
​auto-committed.​ ​transaction.​ ​5. ORDER BY vs. GROUP BY​
​ORDER BY Clause​ ​GROUP BY Clause​

​5. Speed/Logging​ ​ aster​​as it removes metadata​


F ​ lower​​as it logs a​
S
​and deallocates space with​ ​transaction for every​
​minimal transaction logging.​ ​deleted row, using a buffer.​ ​ . Primary​
1 ​Sorts​​the result set.​ ​Aggregates​​rows into groups.​
​Purpose​

​4. NATURAL JOIN vs. EQUI JOIN​ ​ . Effect on​


2 ​ ffects the​​display order​​of​
A ​ ollapses​​multiple rows into a​
C
​Rows​ ​the final rows/groups.​ ​single summary row per group.​
​NATURAL JOIN​ ​EQUI JOIN​

​ . Execution​
3 ​ pplied​​last​​in the SQL​
A ​ pplied​​before​​HAVING​​and​
A
​1. Join Condition​ ​ oins tables​​automatically​
J ​ oins tables using an​
J ​Order​ ​query execution (after all​ ​ORDER BY​​(after​​WHERE​​).​
​based on all columns with​ ​explicit equality condition​ ​other clauses).​
​matching names​​and data​ ​(​=​) in a​​WHERE​​or​​ON​
​types.​ ​clause.​

​ . Aggregate​
4 I​s​​optional​​and not directly​ I​s​​required​​whenever​
​Function​ ​tied to aggregate functions.​ ​non-grouped columns are used​
​ . Common​
2 ​ he common column(s) are​
T ​ he common column(s) are​
T ​with aggregate functions in the​
​Column Output​ ​displayed​​only once​​in the​ ​displayed​​twice​​(once for​ ​SELECT​​list.​
​result set.​ ​each table) in the result set.​

​ . Sorting​
5 ​ llows sorting in​
A ​ oes​​not​​inherently imply any​
D
​3. Operator Used​ ​ o​​explicit comparison​
N ​ xplicitly uses the​​equals​
E ​Direction​ ​Ascending​​(​ASC​​) or​ ​sorting or display order.​
​operator is used in the join​ ​operator​​(​=​) for​ ​Descending​​(​DESC​​) order.​
​clause.​ ​comparison.​

I​t looks like there are some spelling errors in your request. I'll define the concepts based on​
​the most likely correct terms in the context of Database Management Systems (DBMS) and​
​SQL.​
​Here are the definitions:​
​Term​ ​ ikely Correct​
L ​Definition​
​Term​
​Database/Relational Concepts​
​Term​ ​ ikely Correct​
L ​Definition​
​Term​ ​ ltenative​
a ​Alternate Key​ ​ ​​candidate key​​that is​​not chosen​​to be the​
A
​keys​ ​primary key for the relation.​

r​ efrative​ ​ eferential​
R ​ rule stating that if a​​foreign key​​column in one​
A
​integeratiy​ ​Integrity​ ​table references a​​primary key​​in another table,​ ​ rimary​
p ​ rimary Key​
P ​ column or set of columns that​​uniquely​
A
​the values in the foreign key must either be​​null​ ​keys​ ​(PK)​ ​identifies​​each​​row​​in a table. It cannot contain​
​or​​match​​an existing value in the primary key.​ ​NULL​​values and must be unique.​
​This prevents orphaned records.​

​ andiitve​
c ​ andidate​
C ​ column or set of columns that could potentially​
A
​ingerarty​ ​Integrity​ ​ efers to the​​accuracy, consistency, and​
R ​key​ ​Key​ ​be a primary key because it​​uniquely identifies​
​reliability​​of data stored in a database. It is​ ​each row and is​​minimal​​(no proper subset is​
​typically enforced using​​constraints​​.​ ​also a superkey).​

​relation​ ​ elation​​(or​
R ​ collection of data organized into rows and​
A ​constraibs​ ​Constraints​ ​ ules enforced on data columns to​​limit the type​
R
​Table)​ ​columns. In the relational model, a table​ ​of data​​that can be inserted, updated, or deleted.​
​represents a​​set of entities​​(rows) and their​ ​They ensure data integrity (e.g.,​​PRIMARY KEY​​,​
​attributes​​(columns).​ ​FOREIGN KEY​​,​​NOT NULL​​,​​UNIQUE​​,​​CHECK​​).​

​ omain​
d ​Domain​ ​ he​​set of allowed values​​for an attribute​
T
​name​ ​(column). For example, the domain for a​ ​SQL Functions and Operators​
​'CustomerAge' column might be integers​
​between 0 and 150.​ ​Term​ ​ ikely Correct​
L ​Definition​
​Term​

​cardinaly​ ​Cardinality​ ​ he number of​​rows​​(or tuples) in a relation​


T
​(table). It represents the​​count of entities​​in the​ ​ grigative​
a ​ ggregate​
A ​ unctions that​​perform a calculation​​on a set of​
F
​set.​ ​functions​ ​Functions​ ​rows and return a single summary value.​
​Common examples include​​COUNT()​​,​​SUM()​​,​
​AVG()​​,​​MAX()​​, and​​MIN()​​.​

​altributes​ ​ ttribute​​(or​
A ​ characteristic or property of a relation (table).​
A
​Column)​ ​Each attribute has a specific​​name​​and​​domain​​.​
​like​ ​ IKE​
L ​ logical operator used in the​​WHERE​​clause to​
A
​Operator​ ​search for a specified pattern​​in a column. It is​

​Keys and Constraints​


​ sed with​​wildcard characters​​(e.g.,​​%​​for zero​
u
​or more characters,​​_​​for a single character).​

You might also like