0% found this document useful (0 votes)
7 views

week 5 db assignment

Uploaded by

creativpetath
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)
7 views

week 5 db assignment

Uploaded by

creativpetath
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/ 21

ANSWERS TO 46 QUERIES.

Q2 Here 200 SQL Functions nd their mening:

1. AVG() - Average value


2. COUNT() - Count of rows
3. MAX() - Maximum value
4. MIN() - Minimum value
5. SUM() - Sum of values
6. GROUPING() - Groups rows based on expression
7. STDEV() - Standard deviation
8. VAR() - Variance
9. VARIANCE() - Variance
10. LISTAGG() - Concatenates values
11. STRING_AGG() - Concatenates strings
12. ARRAY_AGG() - Concatenates arrays
13. PERCENTILE_CONT() - Continuous percentile
14. PERCENTILE_DISC() - Discrete percentile
15. MEDIAN() - Median value
16. MODE() - Most frequent value
17. RANK() - Ranks rows
18. DENSE_RANK() - Dense ranks rows
19. ROW_NUMBER() - Assigns row numbers
20. NTILE() - Divides rows into groups
21. LAG() - Accesses previous row
22. LEAD() - Accesses next row
23. FIRST_VALUE() - First value in group
24. LAST_VALUE() - Last value in group
25. NTH_VALUE() - Nth value in group
26. LISTAGG WITH ORDER BY - Concatenates values with order
27. SUM(DISTINCT) - Sum of unique values
28. AVG(DISTINCT) - Average of unique values
29. MAX(DISTINCT) - Maximum unique value
30. MIN(DISTINCT) - Minimum unique value
31. CONCAT() - Concatenates strings
32. LENGTH() - String length
33. LOWER() - Converts to lowercase
34. UPPER() - Converts to uppercase
35. INITCAP() - Capitalizes first letter
36. SUBSTR() - Substring extraction
37. INSTR() - Finds substring position
38. REPLACE() - Replaces substring
39. TRANSLATE() - Translates characters
40. TRIM() - Removes leading/trailing chars
41. LTRIM() - Removes leading chars
42. RTRIM() - Removes trailing chars
43. REGEXP_SUBSTR() - Regular expression substring
44. REGEXP_INSTR() - Regular expression position
45. REGEXP_REPLACE() - Regular expression replace
46. SOUNDEX() - Phonetically matches strings
47. DIFFERENCE() - Measures string similarity
48. SIMILARITY() - Measures string similarity
49. LEVENSHTEIN_DISTANCE() - Measures edit distance
50. NORMALIZE() - Normalizes Unicode strings
51. UNISTR() - Converts to Unicode string
52. TO_CHAR() - Converts to character string
53. TO_DATE() - Converts to date string
54. TO_NUMBER() - Converts to numeric string
55. TO_TIMESTAMP() - Converts to timestamp string
56. ASCII() - Returns ASCII value
57. CHR() - Returns character by ASCII value
58. UNISTR() - Converts to Unicode string
59. REVERSE() - Reverses string
60. REPEAT() - Repeats string
61. LPAD() - Left-pads string
62. RPAD() - Right-pads string
63. TRUNC() - Truncates string
64. GREATEST() - Returns greatest string
65. LEAST() - Returns least string
66. NULLIF() - Returns NULL if equal
67. COALESCE() - Returns first non-NULL value
68. CASE() - Conditional expression
69. DECODE() - Conditional expression
70. NVL() - Replaces NULL with value
71. ABS() - Absolute value
72. ACOS() - Arc cosine
73. ASIN() - Arc sine
74. ATAN() - Arc tangent
75. COS() - Cosine
76. COSH() - Hyperbolic cosine
77. SIN() - Sine
78. SINH() - Hyperbolic sine
79. TAN() - Tangent
80. TANH() - Hyperbolic tangent
81. EXP() - Exponential
82. LN() - Natural logarithm
83. LOG() - Logarithm
84. POWER() - Raises to power
85. ROUND() - Rounds to nearest integer
86. TRUNC() - Truncates to integer
87. FLOOR() - Rounds down
88. CEIL() - Rounds up
89. MOD() - Modulus
90. REMAINDER() - Remainder
91. SIGN() - Sign of number
92. SQRT() - Square root
93. CBRT() - Cube root
94. FACTORIAL() - Factorial
95. NOW()_Returns the current date and time
96. CURDATE()_Return the current date
97. CURTIME()_Return the current time
98. DATEDIFF()_Return the difference between two dates
99. DATEDD()_Adds a specified time interval to a date
100. DATEDIFF()_Returns the difference in days between two dates
101. EXTRACT()_Retrieves subparts
102 FORMRT()_Formats a date or time value according to a specific format
103 STR_TO_DATE()_Converts a string to a data using a specified format
104 LAST_DAY()_Returns the last day of the month for given date
105 ABS()_Returns the absolute value of number
106 CEIL()_Rounds a number up to the nearest integer
107 FLOOR()_Rounds a number down to the nearest integer
108 ROUND()_Rounds a number to specified number of decimal places
109 RAND()_Returns a random floating point value between 0 and 1
110 POWER()_Returns the value of a number raised to the power of another number
111 SQRT()_Returns the square root of a number
112 EXP()_Returns the value of erased to the power of a given number
113 LOG()_Returns the natural logarithm of a number
114 MOD()_Returns the remainder of a division operation
115 CASE:Evaluates conditions and returns a value based on the result
116 COALESCE: Returns the firs non null value in a list
117 NULLIF: Returns null if two expressions are equal otherwise returns the first expression
118 IF()_Returns one value if a condition is true and another value if false
119 DECODE()_Performs conditional checks and returns a value based on the result
120 CAST()_Converts a value from one data type to anther
121 CONVERT()_Converts a value from one data type to another with options
122 TO_CHAR()_Convert a number or date to a string
123 TO_DATE()_Converts a string to a date
124 TO_NUMBER()_Converts a string to a number
125 ROW_NUMBER()_Assign a unique special integer to rows within a partition
126 RANK()_Assigns a rank to each row within a partition of a result
127 DENSE_RANK()_Similar to rank but without gaps in the raning values
128 NTILE()_Divides an ordered partition into a specified number of groups
129 SUM_OVER()_Calculates a cumulative sum across a specified window
130 JSON_EXTRACT()_Extract data from a json file
131 JSON_OBJECT ()_Creates a json object from key_value
132 JSON_ARRAY()_Creates a json array from a set of value
133 JSON_AGG()_Aggregates a value into a json array
134 JSON_VALID()_Checks if a string is valid json
135 ISNULL()_Checks whether an expression is null
136 IFNULL()_Returns a specified value if the expression is null
137 CASE WHEN:A condition statement that returns values based on specified conditions
138 SET: Used to assign a value to a variable
139 EXISTS()_checks for the existence of any record in a subquery
140 USER()_Returns the current database user
141 CURRENT_USER()_Returns the current of the user connected to the database.
142 DATABASE()_Returns the name of the current database
143 VERSION()_Returns the version of the database
144 SESSION_USER()_Returns the name of the current session user
145 SHA1()_Returns the SHA1 hash of a string
146 MD5()_Returns the MD5 hash of string
147 PASSWORD()_Encrypts a password
148 ENCRYPT()_Encrypt a string using a specified algorithm
149 DECRYPT()_Decrypt a string
150 XMLAGG()_Aggregates xml data into a single xml value
151 EXTRACTVALUE()_Extracts a value from an xml document
152 UPDATEXML()_Updates an xml document with a new value
153 XMLFOREST()_Create xml elements from specified columns
154 XMLPARSE()_Parase a string into an xml type
155 GENERATE_SERIES()_Generates a series of values
156 FORMAT()_Formats a value
157 STRING_AGG()_ Concatenates values into a single string with a specified separator
158 UUID()_Generate a vniversally unique identifier
159 SYSDATE()_Returns the current date and time
160 CREATE()_Use to createa new database or table
161 DROP()_Use to delete a database or table
162 ALTER()_Modifies an existing database or table structure
163 TRUNCATE()_Removes all rows from a table without logging individual deletions
164 MERGE()_Performs an upsert operation
165 COMMIT()_Saves all changes made in the current transaction
166 ROLLBACK()_Undoes changes made in the current transaction
167 SAVEPOINT()_Sets a point within a transaction to which you can later roll
168 SET TRANSACTION: Configures the properties of the current transaction
169 EXPLAIN()_Provides information on how a query will be executed
170 ANALYZE()_Collects statistics about the contents of tables to optimize query execution
171 OPTIMIZE TABLE()_Reorganizes the physical storage of table data to improve performance
172 WITH RECURSIVE: Enbles recursive common table expressions
173 CTE: Allows defining temporary result sets for queries
174 PARTITION BY: Divides the result set into partitions to apply window function
175 REPLACE()_Replaces all occurrences of a substring with another string.

Q2 T_SQL (Transact-SQL) is a programming language used for managing and manipulating data in
Microsoft SQL Server and other compatible databases. It's an essential skill for database
administrators, developers, and analysts.

1. CREATE TABLE
- Creates a new table.
- Example: CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(255), email
VARCHAR(255));

2. ALTER TABLE
- Modifies an existing table.
- Example: ALTER TABLE customers ADD address VARCHAR(255);

3. DROP TABLE
- Deletes a table.
- Example: DROP TABLE customers;

1. LEN()
- Returns the length of a string.
- Example: SELECT LEN('Hello World');

2. UPPER()
- Converts a string to uppercase.
- Example: SELECT UPPER('hello');

3. SUM()
- Calculates the sum of a column.
- Example: SELECT SUM(salary) FROM customers;

Q4 A livelock is a situation where two or more processes are constantly trying to acquire resources,
but are unable to do so due to conflicting actions.

Example:

Process A:

1. Tries to lock resource R1


2. Finds R1 locked by Process B
3. Unlocks own resource R2 (to try again)
4. Tries to lock R1 again

Process B:

1. Tries to lock resource R2


2. Finds R2 unlocked (by Process A)
3. Locks R2
4. Tries to lock R1 again
A deadlock is a situation where two or more processes are blocked indefinitely, each waiting for the
other to release a resource.

Example:

Process A:

1. Locks resource R1
2. Requests resource R2 (locked by Process B)
3. Waits for R2

Process B:

1. Locks resource R2
2. Requests resource R1 (locked by Process A)
3. Waits for R1

You might also like