Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
7 views
Import Theory Question - SQL
Computer
Uploaded by
prabumanikanda175
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Import Theory Question - SQL(1) For Later
Download
Save
Save Import Theory Question - SQL(1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
7 views
Import Theory Question - SQL
Computer
Uploaded by
prabumanikanda175
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Import Theory Question - SQL(1) For Later
Carousel Previous
Carousel Next
Save
Save Import Theory Question - SQL(1) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 5
Search
Fullscreen
Important Theory Questions - Must Read SQL 1, Degree - It refers to the number of columns in a relation Cardinality - It refers to the number of rows in a relation 2. Domain - A domain is a set of values that can be assigned to an attribute 3. Keys in a Relational Database: (i) Primary Key It is an attribute or set of attributes that uniquely identifies a tuple in a relation. (ii) Candidate Key: The attributes of a table which are eligible to be set as primary key are called as candidate key. (iii) Alternate Key: From the list of candidate key one is chosen as primary key and the remaining are called Alternate key. (iv) Foreign Key: = A Foreign Key is a field (or collection of fields) in one table that uniquely identifies a row of another table. * It is used to establish a link between the data in two tables Candidate Key ‘Alternate Key Unique Key 4. Constraints: Constraints are certain types of restrictions on the data values that an attribute can have. Constraint pel eetelstoe NOT NULL Ensures that a column cannot have NULL values where NULL means missing/ unknown /not applicable value. UNIQUE Ensures that all the values in a column are distinct/unique. DEFAULT A default value specified for the column if no value is provided. PRIMARY KEY The column which can uniquely identify each row or record in a table. FOREIGN KEY The column which refers to value of an attribute defined as primary key in another table. © seaeed with OK Scanner5. Difference between Char and Varchar Data type: char varchar Used for fixed-length character Used for variable-length character strings. strings. It can store maximum of 255 It can store maximum of 65,535 characters characters It pads unused space with blanks | It holds only the characters assigned to it. Memory allocation is static ‘Memory allocation is dynamic Faster than VARCHAR due to fixed | Slower than CHAR due to variable size. length 6. SQL Commands: (i) DDL(Data Definition Language): > create > alter > drop > truncate (ii) DML(Data Manipulatrion Language): > insert > update > delete 7. Difference Primary Key and Unique Key Primary Key Unique Key Identifies an individual tuple uniquely in a relation Uniquely identifies each tuple (row) ina table. [or table, Only one primary key per table. Multiple unique keys can exist for a table, Does allow NULL values for the column. Allows NULL value for the column. Keyword used to assign constraint : primary key | Keyword used to assign constraint : unique 8: Characteristics of Primary key: + Aprimary key uniquely identifies each row (record) within a table. + It does not allow duplicate entries in a table. + The primary key attribute(s) cannot contain mull values. + There can be only one primary key attribute in a table. 9. where clause: The where clause is used to filter the records of a table based on the specified condition 10 . group by: GROUP BY statement is used to group rows based on values in one or more columns. It's particularly useful when you want to calculate aggregate values (such as count, average, sum, or maximum) for each group. © seaeed with OK Scanner11. Having Clause: + The HAVING clause in SQL is used to filter query results based on aggregate functions and groupings, «The HAVING clause allows you to filter groups of data after using the GROUP BY clause. 12. Order by: * The ORDER BY clause is used to sort the result set in either ascending or descending order based on one or more columns. + By default, the ORDER BY command sorts the result set in ascending order. + Ifyou want to sort the records in descending order, you can use the DESCkeyword. SELECT * FROM Customers ORDER BY CustomerName DES\ 13. Difference where and having ‘WHERE Clause HAVING Clause Used to filter rows of a table. ‘User to filter the grouped data. It can be used without GROUP BY clause. ‘To be used with GROUP BY clause. Operates on individual records. (Operates on grouped records. Applied before GROUP BY clause. Applied after GROUP BY clause. Cannot contain aggregate functions. ‘Can contain aggregate functions (e.g., SUM, COUNT). Used with SELECT, UPDATE, and DELETE statements. ‘Used only in SELECT statements. 14. Difference delete and ie Data Manipulation Language (DML) command. Data Definition Language (DDL) command. Used to remove records from a table. Used to (i) remove a table from a database (ii) remove a column or constraint from a table (iii) remove/delete a database Space occupied by the table in memory is not freed even if all tuples are deleted. Frees the table space from memory. Syntax DELETE FROM table_name WHERE condition; Syntax - To drop a table: DROP TABLE table_name; - To drop a database: DROP DATABASE database_name: Eg: To remove a record with empid = 1001 from employee table delete from employee where empid = 1001; Eg:To remove/delete the employee table: DROP TABLE employee; Actions can be rolled back. Actions cannot be rolled back. © seaeed with OK Scanner15. Difference Group by and order by: GROUP BY ORDER BY Itis used to groups rows based on the same value in specified columns. It is used sorts the result set in ascending or descending order based on one or more columns. Often used with aggregate functions (e.g., COUNT, SUM, AVG) to compute statistics for groups. Used to arrange the output rows. Requires an aggregate function (e.g., COUNT, SUM) when used. ‘Columns in the SELECT clause must be either part of the grouping columns or aggregate functions. ‘Does not require an aggregate function. ‘Can select any columns in the SELECT clause. SELECT columni, aggregate_function(column2) FROM table GROUP BY column1; SELECT column1, column2 FROM table ORDER BY column ASG; or SELECT column1, column2 FROM table ORDER BY column! DESC; ‘SQL Commands fi) Creating database: Syntax: Create database databaseName; Create database Class11b23; ) Selecting database: Syntax: Use databaseName; Use Class11b23; (iii) To view the available databases: Show databases; (iv) To create a table: Syntax: Create table tableName(col1Name datatype [constraint], Col2Name datatype [constraint], CoIN_Name datatype [constraint]); Student [Field | DataType | Constraint Roll int imary key. Name Varchar(20) not null ‘Age int DOB date Marks int default 20 Create table Student(Roll integer primary key, Name varchar(25) not null, Age integer, DOB date, Marks integer default 20); (v) To view table structure: Syntax: desc tableName; Eg: desc student; (or) describe tableName; (or) describe student; © seaeed with OK Scanner(vi) Inserting records into the table: Syntax: Insert into tableName values(col1 Value, col2Value,..... ColNValue); Eg. Insert into student values(1001, “Hari”, 14, “2009-05-22”, 80); (vii: Update a record: Syntax: Update tableName set colName = newValue where condition; Eg: ‘update student set marks = 94 where roll = 1002; (viii): Delete a record: Syntax: Delete from tableName where condition; Delete from student where roll = 1004; (ix| Add Column: ‘Syntax: Alter table tableName add colName datatype constraint; Eg: ‘Alter table student add class varchar(5); (x) Add Primary to existing table: ‘Syntax: ‘Alter table tableName add PRIMARY KEY (ColName); Eg: ‘Alter table student add primary key (roll); i) Remove Primary Key: Syntax: Alter table tableName drop Primary key; ‘Alter table student drop Primary key; (xii) Remove column: ‘Syntax: Alter table TableName drop colName; Eg: Alter table Student drop class; (xiii) Remove/delete table: ‘Syntax: Drop table tableName; Eg: Drop table Student; (xiv) View the available tables: show tables; (xv): Viewing the table, ing Table: Syntax: Select * from tableName where condition group by columnName having groupConditon order by columnName [asc| dsc]; Select que: © seamed vith one Seamer
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6127)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2543)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Yes Please
From Everand
Yes Please
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel