Wordpress Material Rdbms U 1
Wordpress Material Rdbms U 1
Unit – I
Introduction to Database System and SQL commands
A database environment is a collective system of components that comprise and regulates the
group of data, management, and use of data, which consist of software, hardware, people,
techniques of handling database, and the data also.
1.2 Data, Information, Data Item or Fields, Records, Files, Metadata, Data
dictionary and it’s components,
Data
❖ “DATA is a raw fact, anything can be data”.
❖ It is not be meaningful.
❖ It is used analysis and reasoning.
❖ It is input processing unit.
❖ Data is basic row material which taken by certain observation, certain experiment and
storing in paper, stored memory, human mind.
❖ Ex:- marks of student ,account information
INFORMATION
❖ This is a processed form of the data.
❖ It is always meaningful.
❖ “Meaningful data is called information”.
❖ It is output processing units.
❖ Whenever we organize the data and process is done on it then we get proper
information.
Records:
❖ A record is a collection of logically related fields. For examples, collection of fields (id,
name, society & city) forms a record for customer.
Files:
❖ A group of related records. Files are frequently classified by the application for which
they are primarily used (employee file).
Metadata:
❖ Metadata is data about data.
❖ Data such as table name, column name, data type, authorized user and user access
privileges for any table is called metadata for that table.
Sub-schemas :
❖ It is a subset of schema and inherits the same property that schema has.
Instances :
❖ The contents of the database at any point of time (or current state), it is referred to as
INSATANCE of database.
Syntax:
CREATE TABLE TableName (column1 datatype (size), column2 datatype(size)...ColumnN
datatype(size));
Example:
CREATE TABLE student(Rollno number(15),Name varchar2(20),Age number(5),DOB date);
Output: Table created.
Syntax:
DESCRIBE TableName;
OR
DESC TableName;
Output:
Syntax:
Alter Table TableName Add (NewColumnName1 Datatype (size), NewColumnName2 Datatype
(size)…. NewColumnNameN Datatype (size));
Example:
ALTER TABLE student ADD (marks number (15)); //Add column marks
Output: Table altered.
Syntax:
Alter Table TableName Modify (ColumnName1 NewDatatype (NewSize), ColumnName2
NewDatatype (NewSize)……ColumnNameN NewDatatype (NewSize));
Example: ALTER TABLE student Modify (marks number (20)); // Change size of column
Output: Table altered
Example: ALTER TABLE student DROP COLUMN marks; // Remove marks column
Output: Table altered.
❖ TRUNCATE:
Syntax:
INSERT INTO TableName(ColumnName1, ColumnName2…ColumnNameN) values
(Expression1, Expression2….ExpressionN);
Example:
INSERT INTO Student (Sno, Sname, age, Branch) values (1,’Niyati’, 17,’CE’);
Output: 1 row inserted
Example:
INSERT INTO Student (Sno, Sname, age, Branch) values (1,’Niyati’, 17, NULL);
Example:
UPDATE Student SET Name=’nilam’ WHERE Rollno=1;
Output: 1 row Updated.
NOTE:
❖ In the Update statement, WHERE clause identifies the rows that get affected.
❖ If you do not include the WHERE clause, column values for all the rows get
affected.
Syntax:
DELETE FROM TableName WHERE condition;
Example:
❖ To delete an employee with id 100 from the employee table, the SQL delete query would be
like,
DELETE FROM Student WHERE Rollno = 100;
❖ To delete all the rows from the employee table, the query would be like,
DELETE FROM Student;
❖ The SELECT command is used to retrieve selected rows from the Tables.
Syntax:
a. SELECT * FROM TableName;
b. SELECT ColumnName1, ColumnName2… ColumnNameN From TableName;
c. SELECT * FROM TableName WHERE Condition;
Example:
Explicit Commit:
❖ Syntax:
COMMIT;
❖ Output:
Commit complete
Implicit Commit:
❖ There are some operations which forces a COMMIT to occur automatically, even user
don’t specify the COMMIT command.
❖ Some of commands are given below:
Quit Command:
To end SQL*PLUS session disconnecting from the Oracle.
Exit Command:
To end SQL*PLUS session disconnecting from the Oracle.
❖ Syntax:
ROLLBACK TO SAVEPOINT savepoint_name;
❖ Output:
Rollback Complete.
❖ Syntax:
SAVEPOINT savepoint_name;
❖ Output:
Savepoint created.
Syntax:
❖ The owner of a database object can grant all privileges or specific privileges to other
users.
❖ The WITH GRANT OPTION allows the grantee. User to which privilege is granted to
in turn grant object privilege to other users.
❖ User can grant all or specific privileges owned by him/her.
Example:
GRANT ALL
ON Customer
TO user2
WITH GRANT OPTION;
Output:
Grant Succeeded.
❖ Observe the use of WITH GRANT OPTION. If this option is not specified, user2 will
have privileges, but he cannot grant these privileges to other users.
Example:
Revoke SELECT, INSERT
ON Customer
FROM user2;
GRANT REVOKE
This DCL command grants permissions to the This DCL command removes permissions if
user on the database objects. any granted to the users on database objects.
It assigns access rights to users. It revokes the user access rights of users.
When the access is decentralized granting If decentralized access removing the granted
permissions will be easy. permissions is difficult.