SQL Interview Question Part 1
Q 1. How do you select all records from
the table?
Answer :- Select * from table_name;
Q 2. What is a join?
Answer :- Join is a process of retrieve
pieces of data from different sets (tables) and returns them to the
user or program as one “joined” collection of data.
Q 3. How do you add record to a table?
Answer :- INSERT into table_name VALUES
(‘TEST’, 33 , ‘M’);
Q 4. How do you add a column to a
table?
ALTER TABLE Department ADD (AGE,
NUMBER);
Q 5. How do you change value of the
field?
Answer :- UPDATE EMP_table set number =
200 where item_munber = ‘CD’;
update name_table set status = 'enable'
where phone = '4161112222';
update SERVICE_table set REQUEST_DATE =
to_date ('2006-03-04 09:29', 'yyyy-mm-dd hh24:MM') where phone =
'4161112222';
Q 6. What does COMMIT do?
Answer :- Saving all changes made by
DML statements
Q 7. What is a primary key?
Answer :- The column (columns) that has
completely unique data throughout the table is known as the primary
key field.
Q 8. What are foreign keys?
Answer :- Foreign key field is a field
that links one table to another table’s primary or foreign key.
Q 9. What is the main role of a primary
key in a table?
Answer :- The main role of a primary
key in a data table is to maintain the internal integrity of a data
table.
Q 10. Can a table have more than one
foreign key defined?
A table can have any number of foreign
keys defined. It can have only one primary key defined.
Q 11. List all the possible values that
can be stored in a BOOLEAN data field.
There are only two values that can be
stored in a BOOLEAN data field: -1(true) and 0(false).
Q 12. What is the highest value that
can be stored in a BYTE data field?
Answer :- The highest value that can be
stored in a BYTE field is 255. or from -128 to 127. Byte is a set of
Bits that represent a single character. Usually there are 8 Bits in a
Byte, sometimes more, depending on how the measurement is being made.
Each Char requires one byte of memory and can have a value from 0 to
255 (or 0 to 11111111 in binary).
Q 13. Describe how NULL work in SQL?
The NULL is how SQL handles missing
values. Arithmetic operation with NULL in SQL will return a NULL.
Q 14. What is Normalization?
Answer :- The process of table design
is called normalization.
Q 15. What is Trigger?
Answer :- Trigger will execute a block
of procedural code against the database when a table event occurs.
A2. A trigger defines a set of actions that are performed in response
to an insert, update, or delete operation on a specified table. When
such an SQL operation is executed, in this case the trigger has been
activated.
Q 16. Can one select a random
collection of rows from a table?
Answer :- Yes. Using SAMPLE clause.
Example:
SELECT * FROM EMPLOYEES SAMPLE(10);
10% of rows selected randomly will be
returned.
Q 17. You issue the following query:
SELECT FirstName FROM StaffList WHERE
FirstName LIKE '_A%‘
Which names would be returned by this
query? Choose all that apply.
Allen
CLARK
JACKSON
David
Answer :- JACKSON
Q 18. Write a SQL SELECT query that
only returns each city only once from Students table? Do you need to
order this list with an ORDER BY clause?
Answer :- SELECT DISTINCT City FROM
Students;
Q 19. What is DML and DDL?
Answer :- DML and DDL are subsets of
SQL.
DML stands for Data Manipulation
Language and DDL – Data Definition Language.
DML consist of INSERT, UPDATE and
DELETE
DDL commands
CREATE TABLE, ALTER TABLE, DROP TABLE,
RENAME TABLE, CREATE INDEX, ALTER INDEX, DROP INDEX.
CREATE/ALTER/DROP VIEW
Q 20. Write SQL SELECT query that
returns the first and last name of each instructor, the Salary, and
gives each of them a number.
Answer :- SELECT FirstName, LastName,
Salary, ROWNUM FROM Instructors;
No comments:
Post a Comment