Page 284 - PYTHON-12
P. 284
3. What are DDL and DML statements?
Ans. DDL statements are used for creating or deleting tables, views, etc. DML statements are used for manipulating
values for records in a table.
4. What is a base table?
Ans. A base table is a table from which the values can be derived for another table. For example, in case of views,
the values are extracted from the base table on which the view depends.
5. What is NULL value?
Ans. A NULL value in a table is a value in a field which is blank. This means that a field with a NULL value is a
field with no value; not even zero is entered.
6. What is a NOT NULL constraint?
Ans. If you do not want a column to have a NULL value, then you need to define such a constraint on this
column specifying that NULL is now not allowed for that column.
7. (a) What do you mean by Primary Key? Give a suitable example of a Primary Key from a table containing
some meaningful data.
Ans. An attribute or a set of attributes which is used to identify a tuple (row) uniquely is known as
Primary Key.
Table: Students
Admission_No First Name Last Name DOB
27354 Jatin Kumar 05-02-1998
25350 Mona Sinha 24-09-2004
26385 George Moun 19-05-1997
16238 Mukesh Kumar 24-09-2004
Admission_No. is the Primary Key because this column will contain unique data for each record.
(b) Write a query that displays city, salesman name, code and commission from salesman table.
Ans. SELECT city, salesman_name, code, commission from salesman;
(c) Write a query that selects all orders except those with zero or NULL in the amount field from table
orders.
Ans. SELECT * from orders where amount IS NOT NULL;
(d) Write a command that deletes all orders for the customer SOHAN from table customer.
Ans. DELETE from customer where customer_name is LIKE ‘SOHAN’;
(e) Differentiate between DROP and DELETE command.
Ans. DROP command is used to drop a table along with all the records stored in it whereas DELETE command
is used to delete all the records or some of the records from a table without deleting the table.
(f) How can you add a new column or a constraint in a table?
Ans. If you want to add a new column in an existing table, ALTER command is used. For example, to add a
column bonus in a table emp, the statement will be given as:
ALTER table emp ADD
Computer Science with Python–XII 12.54 Ans. Yes, we can add more than one column by using the ALTER TABLE command. Multiple column names are
(bonus Integer);
(g) Can you add more than one column in a table by using the ALTER TABLE command?
given, which are separated by commas, while giving with ADD. For example, to add city and pin code in
a table employee, the command can be given as:
ALTER table employee
ADD (city CHAR(30), PINCODE INTEGER);