Page 285 - PYTHON-12
P. 285
(h) What are JOINS?
Ans. A JOIN is a query that combines tuples from more than one table. In a join query, the table names are
given with FROM clause, separated by a comma. For example,
SELECT name, salary
FROM emp1, emp2;
In this statement, the two tables are emp1 and emp2 from which the column name and salary are
extracted.
8. How can you eliminate duplicate records in a table with select query?
Ans. The DISTINCT clause is used with SELECT statement to hide duplicate records in a table. For example, to
display cities from table suppliers.
SELECT DISTINCT city FROM suppliers;
9. How can you DROP a UNIQUE Constraint?
Ans. To drop a UNIQUE constraint, use the following SQL statement:
ALTER TABLE SUPPLIER
DROP CONSTRAINT chkcommission;
Here, the constraint chkcommission is deleted from the table supplier.
10. Define a Foreign Key.
Ans. A foreign key is a key which is used to link two tables together. It is also called a referencing key. Foreign
key is a column or a combination of columns whose values match a primary key in a different table. The
relationship between two tables matches the primary key in one of the tables with a foreign key in the
second table. If a table has a primary key defined on any field(s), then you cannot have two records having
the same value of that field(s).
11. Define the various SQL Constraints.
Ans. Constraints are the rules enforced on data or columns on a table. These are used to restrict the values that
can be inserted in a table. This ensures data accuracy and reliability in the database.
Following are the most commonly used constraints available in SQL:
(a) NOT NULL Constraint: Ensures that a column cannot have NULL value.
(b) DEFAULT Constraint: Provides a default value for a column when no value is specified.
(c) UNIQUE Constraint: Ensures that all values in a column are unique. There should not be any redundant
value in a column which is being restricted.
(d) PRIMARY Key: Uniquely identifies each row/record in a database table.
(e) FOREIGN Key: Uniquely identifies a row/record in any other database table.
(f) CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions.
For example, to restrict the salary column that it should contain salary more than ` 10,000.
12. Consider the following tables: COMPANY and MODEL.
Table: Company
Comp_ID CompName CompHO ContactPerson
1 Titan Okhla C.B. Ajit
2 Ajanta Najafgarh R. Mehta
3 Maxima Shahdara B. Kohli
4 Seiko Okhla R. Chadha
Relational Database and SQL
5 Ricoh Shahdara J. Kishore
Note:
(a) Comp_ID is the Primary Key.
12.55