SQL
SQL
1.Which of the following attributes can be considered as a choice for primary key?
a) Name b) street c) Roll no d) subject
5. Which of the following keywords will you use in the following query to display the
unique values of a column dept_name!
Select dept_name from company:
a) ALL c) Distinct
b) From d) Name
6. The clause of select query allows us to select only those rows in the result
satisfy aspecified condition.
a)where c)having
b)from d)like
12. The constraint ensure that all values in a column are distinct
e) DEFAULT b)UNIQUE c)CHECK d)NOT NULL
13. The constraint ensures that all values in a column satisfy certain condition
f) DEFAULT b)UNIQUE C) CHECK d) NOT NULL
These commands are used to define the database structure, alter and drop the database.
These commands are used to manipulate,access the data of a database ,it is used to extract
the desired data from the database
DML provides data manipulation techniques like insertion , update & delete data
DML facilitates the use of relationship between the records
DML provides independence of programming language by supporting higher level
language
These commands are used to provide the security to the data in a database object.
Create command is used to create a new table involves naming the table, defining the column
attributes their data type & size.
Syntax: Ex:
An alter command is used to modify a table by adding a new column or changing the data type of
column or deleting the column
Syntax: Ex:
Alter table tablename Alter table Student
Add Add
( (
Columnname1 Datetype1, Total Number (3),
Columnname2 Datetype2 Percentage Number (5,2)
); );
Drop command is used delete the entire table from database permanently.
OR
Is used to remove the table definition along with the data
Syntax Ex:
Ex:
Insert into student values(101,’anu’,’12-may-20’);
11. Explain the different forms of select command with an ex
.
Select command is used to extract the desired data from a table.
Syntax: Ex:
Select * from tablename Select * from student
Where condition; where (regno=105);
Syntax: Ex:
Update Tablename Update student
Set Set
Columnname=value; Percentage=total/6;
Delete command is used to delete the existing records from the table .
Syntax: Ex:
Delete from tablename ; Delete from student;
14. Write the difference between DROP and DELETE command in SQL.
Drop Delete
Is used to remove the table definition It is used to remove the data in a table
Along with the data
Syntax: Syntax:
Drop table Tablename; Delete From Tablename where(condition);
Ex: Ex:
Drop table student Delete From Student
Where comb=’pcmb’;
15.Write the syntax of Desc(Describe) command with an ex.
It is used to display the name of the table,column name,data type ,size and along with the
constraints.
Syntax:
Desc tablename;
Where clause is used to extract specific rows that satisfies a condition & displays only the column
specified in the select clause.
Syntax:
Order by clause is used to sort the data in ascending order or descending order
Based on one or more column by default it will be arranged in the ascending order
Syntax Ex:
Select * Select *
From table name from student
Where condition where (result=’pass’)
Order by columnname; order by regno;
Syntax:
Select * from tablename
Where condition
Group by columnname1
Order by columnname1;
Ex: To display the list of all students in each combination
It is used to eliminate all the duplicate records and fetching only the unique records from the table.
Syntax:
Select distinct columnname from tablename;
Ex:
Select distinct rollno from student;
SQL>COMMIT;
ROLLBACK command is used to undo transactions that have not already been saved to the database.
SQL> ROLLBACK;
Max() This function is used to get the maximum value from a column
Ex: select MAX(CS) from student;
MIN() This function is used to get the minimum value from a column
Ex: select Min(cs) from student;
AVG() This function is used to get the average value from a numerical
column
Ex: select AVG(cs) from student;
SUM() This function is used to get the sum value from a numerical column
Ex: select SUM(cs) from student;
COUNT() It returns the number of value where expression is not null
Count(*) It returns the number of value in a table including duplicate & null
value
Select count(*) from student where result=’pass’;
Operators Description
All The all operator is used to compare a value to all values in another
value set
And The and operator allows the existence of multiple conditions in an sql
statements where clause.
Or The or operator is used to combine multiple conditions in an sql
statements where clause.
Exist The exist operator is used to search for the presence of a row in a
specified table that meets certain criteria
Not The not operator reverses the meaning of the logical operator
Function Description
NULL Value:-A NULL value in a table is a value in a field that appears to be blank.
NOT NULL Value:-It ensures that a column cannot have a null value.
UNIQUE:-It ensures all the values in a column are different.
PRIMARY KEY:-It uniquely identifies each row or record in a data base table.
FOREIGN KEY:-It uniquely identifies each row or record in any other data base table.
DEFAULT:-It provides a default value for a column when none is specified.
CHECK: It ensures that all values in a column satisfy certain condition.