Showing posts with label DBMS. Show all posts
Showing posts with label DBMS. Show all posts

Thursday 3 October 2019

What is Super Key, Candidate keys and Alternate Key?

What is Super Key, Candidate keys and Alternate Key?

Super Key
A Super key is any combination of fields within a table that uniquely identifies each record within that table.

managers (table)
ManagerID (unique)

ManagerID+Name=Super Key
ManagerID+Title=Super Key

Candidate keys
Candidate keys are those keys which is candidate for primary key of a table. Candidate keys are such keys which full fill all the requirements of primary key which is not null and have unique records.

Suppose we have a table named Employee which has two columns EmpID and EmpMail, both are not null and have unique value.
Both Field are Candidate keys.

Alternate Key
If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of that table.

Suppose we have a table named Employee which has two columns EmpID and EmpMail, both are not null and have unique value.
So both columns are treated as candidate key.
IF we make EmpID as a primary key, then EmpMail is known as alternate key.

Referential integrity
Referential integrity is a database concept that ensures that relationships between two table remain consistent.

Suppose one table has a foreign key to another table. Referential integrity makes ensure the both have valid record.

products (table)
    id (primary key)

reviews (another table)
    id (primary key),    
    product_id (foreign key)
    review by

One Product can have one Or multiple reviews.
Referential integrity make sure following:
  1. You can't delete record from product table, till review exist in reviews table for same product Id.
  2. You can't add record in reviews table, till you have not added record in product table for same product Id.
  3. If you delete the record from product table, reviews will be deleted automatically using cascade for the same product Id.

Friday 19 August 2016

MongoDB Interview Questions and Answers

 MongoDB Interview Questions and Answers

Question: What is MongoDB?
MongoDB is a cross-platform document-oriented database and classified as a NoSQL database. Its not relational database.
MongoDB works on concept of collection and document.

Question: Is it similar to SQL/MySQL?
No, Its totally different from Relational database.

Question: In which language, MongoDB is written?
C/C++, JavaScript

Question: When First MongoDB was released?

Question: When latest MongoDB was released?
13 July 2016

Question: What is latest version of MongoDB?

Question: Is it opensource?
Yes, It is free to use.

Question: What is offical website of MongoDB?

Question: Compare the Terminology of MongoDB and RDBMS?
Database Database
Table Collection
Tuple/Row Document
column Field
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by mongodb itself)

Question: Compare the Feature of MongoDb?
Feature MySQL MongoDB
Rich Data Model No Yes
Dyamic Schema No Yes
Typed Data Yes Yes
Data Locality No Yes
Field Updates Yes Yes
Easy for Programmers No Yes
Complex Transactions Yes No
Auditing Yes Yes
Auto-Sharding No Yes

Question: What are main feature of MongoDB?
  1. Document-oriented
  2. Ad hoc queries
  3. Indexing
  4. Replication
  5. Load balancing
  6. File storage
  7. Aggregation
  8. Server-side JavaScript execution
  9. Capped collections

Question: What is NoSQL?
It is database which provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases like SQL, Oracle, etc.

Question: What are different type of NoSQL?
  1. Key Value
  2. Column Oriented
  3. Document Oriented
  4. Graph

Question: What is Namespace in MongoDB?
A Namespace is the concatenation of the "database name" and "collection name"

Question: Does  MongoDB provide drivers for PHP?
MongoDB provide the drivers for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang.

Question: What difference between MongoDB and SQL?
MongoDB allows a highly flexible and scalable document structure.
For e.g. one data document in MongoDB can have five columns &  other one in the same collection can have ten columns. Also, MongoDB database are faster as compared to SQL databases due to efficient indexing and storage techniques.

Question: Does MongoDB support foreign key relationships in MongoDB?
No,Its does not support
But we achieve this concept by embedding one document inside another.

Does MongoDB need lot of RAM?
No, It need less than as compare to other database like SQL,MySQL.
MongoDB dynamically allocates and de-allocates RAM based on the requirements of other processes.

Question: What is the structure of ObjectID in MongoDB?
ObjectID is a 12-byte BSON type with:
4 bytes value representing seconds
3 byte machine identifier
2 byte process id
3 byte counter

Question: How many indexes does MongoDB create by default for a new collection?
By default, MongoDB created the _id collection for every collection.

Question: Explain what are indexes in MongoDB?
Indexes are special structures in MongoDB, which stores a small portion of the data set in an easy to traverse form.

Question: What is sharding in MongoDB?
The procedure of storing data records across multiple machines is referred as Sharding.

Question: How can you see the connection used by Mongos?
To see the connection used by Mongos use db_adminCommand ('connPoolStats');

Question: Explain what is a replica set?
A replica set is a group of mongo instances that host the same data set.

Question: Mention what is the command syntax for inserting a document?
database.collection.insert (document).

Question: Explain what is GridFS in MongoDB?
For storing and retrieving large files such as images, video and audio GridFS is used.

Question: What are alternatives to MongoDB?
Cassandra, CouchDB, Redis, Riak, HBase