Category: DBMS


Oracle SQL Codes

oraSqlD01

The whole SQL collection: SQL Codes

select <column_name> from <table_name> where <condition >

insert into <table_name> (<column_name1>,<column_name2>,<column_name3>, . . . ) values (<value1>,<value2>,<value3>,. . .)

create table <table_name>
(column_1    column_dataType,
 column_2    column_dataType,
     …    
 column_n    column_dataType
);

alter table <table name>
add <column_name> <column_dataType>;

ALTER TABLE table_name
ADD (column_1    column_dataType,
     column_2    column_dataType,
     …    
     column_n    column_dataType);

alter table <table name>
drop column <column_name>;

ALTER TABLE <table_name>
 MODIFY <column_name> <column_dataType>;

ALTER TABLE table_name
MODIFY (column_1    column_type,
     column_2    column_type,
     …    
     column_n    column_type );

ALTER TABLE <table_name>
 RENAME COLUMN <old_name> to <new_name>;

ALTER TABLE <table_name>
 RENAME TO <new_table_name>;

ALTER TABLE <table_name>
ALTER COLUMN <column_name> <column_type>;

UPDATE table_name
SET column1=value, column2=value2,…
WHERE some_column=some_value.

rename <old table name > to <new table name>

truncate table < table name>

delete from < table name>

Advertisements

The Whole File:- Sql Interview Questions and Answers

What is the use of CASCADE CONSTRAINTS?
When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.


Why does the following command give a compilation error?

DROP TABLE &TABLE_NAME; Variable names should start with an alphabet. Here the table name starts with an ‘&’ symbol.

Which system tables contain information on privileges granted and privileges obtained?
USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD

Which system table contains information on constraints on all the tables created?obtained?
USER_CONSTRAINTS.


What is the difference between TRUNCATE and DELETE commands?

True

State true or false. !=, <>, ^= all denote the same operation?
True.

State true or false. EXISTS, SOME, ANY are operators in SQL?
True.

What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM(‘!! ATHEN !!’,’!’), ‘!’), ‘AN’, ‘**’),’*’,’TROUBLE’) FROM DUAL;?
TROUBLETHETROUBLE. p>

What does the following query do?
SELECT SAL + NVL(COMM,0) FROM EMP;?
This displays the total salary of all employees. The null values in the commission column will be replaced by 0 and added to salary.

What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.

Which command executes the contents of a specified file?
START or @.

What is the value of comm and sal after executing the following query if the initial value of ‘sal’ is 10000 UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;?
sal = 11000, comm = 1000.

Which command displays the SQL command in the SQL buffer, and then executes it?
RUN.

What command is used to get back the privileges offered by the GRANT command?
REVOKE.

What will be the output of the following query?
SELECT DECODE(TRANSLATE(‘A’,’1234567890′,’1111111111′), ‘1’,’YES’, ‘NO’ );?
NO.

Explanation : The query checks whether a given string is a numerical digit.

Which date function is used to find the difference between two dates?
MONTHS_BETWEEN.

What operator performs pattern matching?
LIKE operator.

What is the use of the DROP option in the ALTER TABLE command?
It is used to drop constraints specified on the table.

What operator tests column for the absence of data?
IS NULL operator.

What are the privileges that can be granted on a table by a user to others?
Insert, update, delete, select, references, index, execute, alter, all.

Which function is used to find the largest integer less than or equal to a specific value?
FLOOR.

Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Data Definition Language (DDL).

****many more****

The Whole File: SQL Server Interview Questions & Answers

1. What is RDBMS?

Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage.

2. What are the properties of the Relational tables?

Relational tables have six properties:

  1. Values are atomic.
  2. Column values are of the same kind.
  3. Each row is unique.
  4. The sequence of columns is insignificant.
  5. The sequence of rows is insignificant.
  6. Each column must have a unique name.

3. What is Normalization?

Database normalization is a data design and organization process applied to data structures based on rules that help building relational databases. In relational database design, the process of organizing data to minimize redundancy is called normalization. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.

4. What is De-normalization?

De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.

5. What are different normalization forms?

  1. 1NF: Eliminate Repeating Groups Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.
  2. 2NF: Eliminate Redundant Data If an attribute depends on only part of a multi-valued key, remove it to a separate table.
  3. 3NF: Eliminate Columns Not Dependent On Key If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key.
  4. BCNF: Boyce-Codd Normal Form If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.
  5. 4NF: Isolate Independent Multiple Relationships No table may contain two or more 1:n or n:m relationships that are not directly related.
  6. 5NF: Isolate Semantically Related Multiple Relationships There may be practical constrains on information that justify separating logically related many-to-many relationships.
  7. ONF: Optimal Normal Form A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.
  8. DKNF: Domain-Key Normal Form A model free from all modification anomalies is said to be in DKNF.

Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.

6. What is Stored Procedure?

A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.

e.g. sp_helpdb, sp_renamedb, sp_depends etc.

7. What is Trigger?

A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.

****many more****

The Whole File: dbms interview

1. What is database?

A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose.

2. What is DBMS?

It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications.

3. What is a Database system?

The database and DBMS software together is called as Database system.

4. What are the advantages of DBMS?

  1. Redundancy is controlled.
  2. Unauthorised access is restricted.
  3. Providing multiple user interfaces.
  4. Enforcing integrity constraints.
  5. Providing backup and recovery.

5. What are the disadvantage in File Processing System?

  1. Data redundancy and inconsistency.
  2. Difficult in accessing data.
  3. Data isolation.
  4. Data integrity.
  5. Concurrent access is not possible.
  6. Security Problems.

6. Describe the three levels of data abstraction?

The are three levels of abstraction:

  1. Physical level: The lowest level of abstraction describes how data are stored.
  2. Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.
  3. View level: The highest level of abstraction describes only part of entire database.

7. Define the “integrity rules”?

There are two Integrity rules.

  1. Entity Integrity: States that “Primary key cannot have NULL value”
  2. Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key value of other relation.

8. What is extension and intension?

  1. Extension: It is the number of tuples present in a table at any instance. This is time dependent.
  2. Intension: It is a constant value that gives the name, structure of table and the constraints laid on it.

****many more****

The Complete Pl/SQL Tutorial

The Complete File: PLSQL

 

  • PL/SQL – Home
  • PL/SQL – Overview
  • PL/SQL – Environment
  • PL/SQL – Basic Syntax
  • PL/SQL – Data Types
  • PL/SQL – Variables
  • PL/SQL – Constants
  • PL/SQL – Operators
  • PL/SQL – Conditions
  • PL/SQL – Loops
  • PL/SQL – Strings
  • PL/SQL – Arrays
  • PL/SQL – Procedures
  • PL/SQL – Functions
  • PL/SQL – Cursors
  • PL/SQL – Records
  • PL/SQL – Exceptions
  • PL/SQL – Triggers
  • PL/SQL – Packages
  • PL/SQL – Collections
  • PL/SQL – Transactions
  • PL/SQL – Date & Time
  • PL/SQL – DBMS Output
  • PL/SQL – Object Oriented

The Complete SQL Tutorial

The Complete file : SQL

.

Basic SQL

  • SQL – Home
  • SQL – Overview
  • SQL – RDBMS Concepts
  • SQL – Databases
  • SQL – Syntax
  • SQL – Data Types
  • SQL – Operators
  • SQL – Expressions
  • SQL – Create Database
  • SQL – Drop Database
  • SQL – Select Database
  • SQL – Create Table
  • SQL – Drop Table
  • SQL – Insert Query
  • SQL – Select Query
  • SQL – Where Clause
  • SQL – AND & OR Clauses
  • SQL – Update Query
  • SQL – Delete Query
  • SQL – Like Clause
  • SQL – Top Clause
  • SQL – Order By
  • SQL – Group By
  • SQL – Distinct Keyword
  • SQL – Sorting Results

Advanced SQL

  • SQL – Constraints
  • SQL – Using Joins
  • SQL – Unions Clause
  • SQL – NULL Values
  • SQL – Alias Syntax
  • SQL – Indexes
  • SQL – Alter Command
  • SQL – Truncate Table
  • SQL – Using Views
  • SQL – Having Clause
  • SQL – Transactions
  • SQL – Wildcards
  • SQL – Date Functions
  • SQL – Temporary Tables
  • SQL – Clone Tables
  • SQL – Sub Queries
  • SQL – Using Sequences
  • SQL – Handling Duplicates
  • SQL – Injection

Head First-SQL

Few DBMS Tutorials

Click on the hyper-linked chapter names given below and download the files ..

1. Introduction

Part 1: Relational Databases
2. Relational Model
3. SQL
4. Advanced SQL
5. Other Relational Languages

Part 2: Database Design
6. Entity-Relationship Model
7. Relational Database Design
8. Application Design and Development

Part 3: Object-Based Databases and XML
9. Object-Based Databases
10. XML

Part 4: Data Storage and Querying
11.Storage and File Structure
12. Indexing and Hashing
13. Query Processing
14. Query Optimization

Part 5: Transaction Management
15.Transactions
16. Concurrency Control
17. Recovery System

Part 6: Data Mining and Analysis
18.Data Analysis and Mining
19. Information Retrieval

Part 7: System Architecture
20. Database System Architectures
21. Parallel Databases
22. Distributed Databases