Database Concepts (Unit – 1) Q1: What is data? Ans1: Data are simply facts or figures, bits of information, but not information itself. Example employee names, product names, addresses, tax codes, registration marks etc. Q2: What is information? Ans2: When data are processed, interpreted, organized, structured or presented so as to make them meaningful or useful, they are called information. Information provides context for data. Example He is going to Delhi. Data Processing Information Q3: What are database properties? Ans3: A database has the following properties: 1) Atomicity: Atomicity in database ensures that the transactions are indivisible and irreducible where transactions either commit or abort. If a part of transaction fails then entire transaction fails. 2) Consistency: Any change in the values of a database at particular instance are consistent with changes to other values 3 Isolation: Transaction in database ensures that the working transaction will not be changed or affected by any other transaction. 4) Durability: Durability of the databases states that “once transaction has been committed, should remain in the same status” even in the case of failures such as Power loss, Database crash, etc. Q4: What are the disadvantage of a File system? Ans4: The disadvantage of a File system is given below 1. Data Redundancy: Data is stored more than once in different files, that means duplicate data or data redundancy may occur in all these files. 2. Inconsistency: In file processing system, various copies of same data may contain different values. Data is not consistent in this system, it means if a data item needs to be changed then all the files containing that data need to be modified. 3. Lack of Data Integration: As data files are independent, accessing information out of multiple files becomes very difficult. Q5: What is Database Management System (DBMS)? Ans5: DBMS or Database Management System is a software application used to access, create, and manage databases. It consists of a group of programs which manipulate the database.DBMS examples include MySQL, Microsoft Access, SQL Server, Oracle, RDBMS, dBase , FoxPro etc.. Application Programs DBMS Software Database Q6: What are the Characteristics of Database Management Systems? Ans6: The main characteristics of a DBMS are as follows: 1 Real-world entity − A modern DBMS is more realistic and uses real-world entities to design its architecture. It uses the behaviour and attributes too. For example, a school database may use students as an entity and their age as an attribute. 2 Relation-based tables − DBMS allows entities and relations among them to form tables. A user can understand the architecture of a database just by looking at the table names. 3 Isolation of data and application − A database system is entirely different than its data. A database is an active entity, whereas data is said to be passive, on which the database works and organizes. 4 Less redundancy − DBMS follows the rules of normalization, which splits a relation when any of its attributes is having redundancy in values. Normalization is a mathematically rich and scientific process that reduces data redundancy. Q7: Define different Types of Users of DBMS. Ans7: Different kinds of users of DBMS are as follows: . 1. Database Administrator (DBA): DBA can be a single person or it can be a group of person. Database Administrator is responsible for everything that is related to database. 2. Application Programmers: Application programmes write application programs to interact with the database 3. End Users: End users are those who access the database from the terminal end. They use the developed applications and they don’t have any knowledge about the design and working of database 4. System Analyst: System analyst is responsible for the design, structure and properties of database. All the requirements of the end users are handled by system analyst. Q8: What are the Advantages of using DBMS? Ans8: Following are the advantages of using a DBMS: 1. Reduction in Redundancy: Unlike traditional file-system storage, Data Redundancy in DBMS is very less or not present. Data Redundancy occurs when the same data are stored unnecessarily at different places. 2 Concurrent Access: – DBMS provide access to multiple users to access the database at the same time. 3. Improved data sharing: The DBMS helps create an environment in which end users have better access to more and better-managed data. 4. Improved Security: A DBMS provides a framework for better enforcement of data privacy and security policies. 5. User Friendly: Using a DBMS, it becomes very easy to access, modify and delete data. Q9: What are the Limitations of using DBMS Approach? Ans9: The main Limitations of using a DBMS: 1. Increased Cost: In order to have a Database Management System, we need to have a high speed processor along with a large memory size which requires an expensive hardware and hence correspondingly expensive software too. 2. Maintenance Cost: Database Management System also calls for a high maintenance cost which includes the cost to maintain the Database Management System once it is made. Q10: What is relational database? Ans10: A relational database is a collection of data items with pre-defined relationships between them. These items are organized as a set of tables with columns and rows. Tables are used to hold information about the objects to be represented in the database. Each column in a table holds a certain kind of data and a field stores the actual value of an attribute. Each row in a table could be marked with a unique identifier called a primary key, and rows among multiple tables can be made related using foreign keys. RDBMS=DBMS+REFERENTIAL INTEGRITY Q11What is Relational Model? Ans11: Relational Model represents how data is stored in Relational Databases. A relational database stores data in the form of relations (tables). In In relational model, 1. A row is called a Tuple. 2. A column is called an Attribute. 3. A table is called as a Relation. 4. The number of attributes in a relation is called degree of relation. 5. The number of rows in a relation is called the Cardinality of a relation. Student Table or relation (Table is known as Relation) Column Row AdmN O 210 211 212 230 Rollno Name Subject Marks 1 2 3 4 Sachin Ramesh Sunita Ritu English Hindi Maths History 80 70 95 80 1. Here AdmNO, Rollno, Name, Subject, Marks are attribute. 2. Here 210, 1, Sachin, English, 80 are field. 3. Number of attribute or column is called the Degree of a relation .So degree of table is 5. 4. Number of rows in a relation is called the Cardinality of a relation. So Cardinality is 4. Student Table or relation (Table is known as Relation) AdmN O 210 211 212 230 Rollno Name Subject Marks 1 2 3 4 Sachin Ramesh Sunita Ritu English Hindi Maths History 80 70 95 80 Student Detail Admno 210 211 Name Sachin Ramesh Address xyz abc Mobile NO 22-55-- Key: A DBMS key is an attribute or set of an attribute which helps you to identify a row (tuple) in a relation (table). Super key: A super key is a group of single or multiple keys which identifies rows in a table. A Super key may have additional attributes that are not needed for unique identification. In student table AdmNo , Roll ,(AdmoNo,Name),(Admno,RollNO ,Name) , (Rollno,Name)are super key. Candidate Key: A candidate key is an attribute or set of an attribute which can uniquely identify a tuple. In Student table AdmNo, Rollno are known as Candidate key. Primary Key: Primary key uniquely identify a record in the table.it is not null also. In Student table AdmNo is primary key. Foreign Key: FOREIGN KEY is a column that creates a relationship between two tables. In Student Detail AdmNo is foreign key to student table. Student Table AdmN O 210 211 212 230 Rollno Name Subject Marks 1 2 3 4 Sachin Ramesh Sunita Ritu English Hindi Maths History 80 70 95 80 SQL is a standard Query language for storing, manipulating and retrieving data in databases. In a database you can define the structure of the data and manipulate the data using some commands. There are two types of languages these are: 1. DDL (Data Definition Language) 2. DML(Data Manipulation Language ) (1) DDL (Data Definition Language) : DDL or Data Definition Language consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database. Examples of DDL commands: CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers). DROP – is used to delete objects from the database. ALTER-is used to alter the structure of the database. TRUNCATE–is used to remove all records from a table, including all spaces allocated for the records are removed. RENAME –is used to rename an object existing in the database. Create Statement CREATE table tablename (column1 datatype, column2 datatype,...columnN datatype primary key(column)); CREATE table Student ( AdmNo integer not null, Rollno Integer, Name varchar(20),subject varchar(10),marks integer, primary key(AdmNo)); Drop Statement The DROP TABLE statement is used to drop an existing table in a database. DROP TABLE tablename; Drop table student (2)DML(Data Manipulation Language ): DML which deals with data manipulation and includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc., and it is used to store, modify, retrieve, delete and update data in a database. SELECT - retrieve data from a database INSERT - insert data into a table UPDATE - updates existing data within a table DELETE - Delete all records from a database table (1) Select Statement SELECT * FROM TableName; SELECT * FROM Student; (2) Insert Statement Insert into tablename (column1, column2,...columnN ) values(value1,value2,...columnN); Insert into Student (AdmNo, Rollno, Name, Subject, marks) values (210, 1, ‘Sachin’,’English’, 80); (3) Update Statement Update tablename set column1=value1, column2=value2… where condition; Update Student Set name=’Sachin Sharma’ where AdmNo=210 (4) Delete Statement DELETE FROM table_name WHERE condition; Delete from student where AdmNo=210;