0% found this document useful (0 votes)
8 views2 pages

Cs ct5 Ans

Uploaded by

VARUN S
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)
8 views2 pages

Cs ct5 Ans

Uploaded by

VARUN S
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
You are on page 1/ 2

CHAR

• Fixed Length: Stores character strings of a fixed length. If the string is shorter than the
specified length, it is padded with extra spaces.

• Storage Size: The storage size is equal to the defined length. For example, CHAR(10) will
always use 10 bytes, regardless of the actual string length

VARCHAR

• Variable Length: Stores character strings of variable length. It only uses as much storage as
needed for the string, plus a few extra bytes for length information.

• Storage Size: The storage size is equal to the actual length of the string plus 2 bytes. For
example, VARCHAR(10) will use between 1 and 12 bytes, depending on the string length

2.To sort the output of a query in ascending or descending order, you use the ORDER
BY clause in SQL. By default, the results are sorted in ascending order. If you want to sort in
descending order, you can use the DESC keyword.
3. the WHERE clause is used to filter records before any groupings are made, while
the HAVING clause is used to filter values after they have been grouped.

Here’s a simple way to remember:


• WHERE is used before grouping (with GROUP BY).
• HAVING is used after grouping to filter groups based on a condition.
8. COMMIT
• Purpose: Permanently saves all changes made during the current transaction
ROLLBACK
• Purpose: Undoes all changes made during the current transaction.
9.Equi Join
• Definition: An Equi Join is a type of join that combines rows from two or more tables
based on a condition that uses the equality operator (=)
Natural Join
• Definition: A Natural Join is a type of join that automatically combines rows from
two tables based on columns with the same name and data type.
10. The COUNT(*) and COUNT() functions in SQL are used to count rows in a table, but they have
some differences:

1. COUNT(*):
o Counts all rows in a table, including those with NULL values.
o It doesn’t require any specific column and is generally used to get the total
number of rows.
2. COUNT(column_name):
o Counts only the rows where the specified column is not NULL.
o Useful when you want to count entries in a specific column and
exclude NULL values.
15. CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY, -- Primary Key constraint
FirstName VARCHAR(50) NOT NULL, -- NOT NULL constraint
LastName VARCHAR(50) NOT NULL, -- NOT NULL constraint
Department VARCHAR(50),
Salary DECIMAL(10, 2) CHECK (Salary >= 20000) -- CHECK constraint
);
16. Sure! Here are the SQL statements for the student table:
(i) SELECT statement using GROUP BY clause
This statement groups students by a specific column, such as Gender, and counts the number
of students in each group.
SELECT Gender, COUNT(*) AS NumberOfStudents
FROM student
GROUP BY Gender;
(ii) SELECT statement using ORDER BY clause
This statement selects all students and orders them by a specific column, such as LastName,
in ascending order.
SELECT *
FROM student
ORDER BY LastName ASC;
You can adjust the column names and conditions based on your specific requirements. If you
need further customization or have any other questions, feel free to ask!
17. Sure! Here’s how you can write a SQL query to select all students whose age is less than 18, using
both GROUP BY and ORDER BY clauses:
SELECT student_id, name, age
FROM students
WHERE age < 18
GROUP BY student_id, name, age
ORDER BY name;
In this query:
• The WHERE clause filters students whose age is less than 18.
• The GROUP BY clause groups the results by student_id, name, and age.
• The ORDER BY clause sorts the results by the name column in ascending order.
If you have any more questions or need further assistance, feel free to ask!

You might also like