Shreya Ism File
Shreya Ism File
The RDBMS is the most popular database system among organizations across the world. It
provides a dependable method of storing and retrieving large amounts of data while offering a
combination of system performance and ease of implementation.
It is a query language used for accessing and modifying information in the database. IBM first
developed SQL in 1970s. Also it is an ANSI/ISO standard. It has become a Standard Universal
Language used by most of the relational database management systems (RDBMS). Some of the
RDBMS systems are: Oracle, Microsoft SQL server, Sybase etc. Most of these have provided
their own implementation thus enhancing its feature and making it a powerful tool.
Few of the sql commands used in sql programming are SELECT Statement, UPDATE
Statement, INSERT INTO Statement, DELETE Statement, WHERE Clause, ORDER BY
Clause,.
In a simple manner, SQL is a non-procedural, English-like language that processes data in groups
of records rather than one record at a time. Few functions of SQL are:
• store data
• modify data
• retrieve data
• modify data
• delete data
• create tables and other database objects
• delete data
1. CHAR : This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of
characters (i.e. the size) this data type can hold is 255 characters. Syntax is CHAR(SIZE)
Example is CHAR (20)
2. VARCHAR : This data type is used to store variable length alphanumeric data. The maximum
this data type can hold is 4000 characters. One difference between this data type and the CHAR
data type is ORACLE compares VARCHAR values using non-padded comparison semantics
i.e. the inserted values will not be padded with spaces. Syntax is VARCHAR(SIZE) Example
is VARCHAR (20) OR VARCHAR2 (20)
3. NUMBER : The NUMBER data type is used to store numbers (fixed or floating point).
4. DATE : This data type is used to represent data and time. The standard format id DD-MM- YY
as in 13-JUL-85. To enter dates other than the standard format, use the appropriate
functions.Date Time stores date in the 24-hour format. By default, the time in a date field is
12:00:00 am,if no time portion is specified. The default date for a date field is the first day of
the current month.
Syntax is DATE
3.To illustrate relational model in DBMS
The relational model represents the database as a collection of relations. A relation is nothing but
a table of values. Every row in the table represents a collection of related data values. These rows
in the table denote a real-world entity or relationship.
The table name and column names are helpful to interpret the meaning of values in each row.
The data are represented as a set of relations.
The Entity Relational Model is a model for identifying entities to be represented in the database
and representation of how those entities are related. The ER data model specifies enterprise
schema that represents the overall logical structure of a database graphically.
The Entity Relationship Diagram explains the relationship among the entities present in the
database. ER models are used to model real-world objects like a person, a car, or a company
and the relation between these real-world objects. In short, the ER Diagram is the structural
format of the database.
1. Attribute: Each column in a Table. Attributes are the properties which define a relation.
e.g., Student_Rollno, NAME,etc.
2. Tables – In the Relational model the, relations are saved in the table format. It is stored
along with its entities. A table has two properties rows and columns. Rows represent
records and columns represent attributes.
3. Tuple – It is nothing but a single row of a table, which contains a single record.
4. Relation Schema: A relation schema represents the name of the relation with its
attributes.
5. Degree: The total number of attributes which in the relation is called the degree of the
relation.
6. Cardinality: Total number of rows present in the Table.
7. Column: The column represents the set of values for a specific attribute.
8. Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.
9. Relation key - Every row has one, two or multiple attributes, which is called relation
key.
10. Attribute domain – Every attribute has some pre-defined value and scope which is
known as attribute domain
Operations in Relational Model
To create a new table within a database, we use the SQL CREATE TABLE statement
Syntax:
<table element>,
<table element>,
);
Example:
id int ,
name varchar (20),
dept varchar(10)
);
11.Insert values into Table
INSERT INTO `table_name` is the command to add data into a table .
Syntax:
Example:
1. A Select statement is a SQL statement that begins with the word "select."
2. Select statements are used to retrieve data from SQL tables.
3. An asterisk after the word "select" means retrieve all fields (columns).
4. The name of the table from which you are retrieving data is specified in the
Fromclause
Syntax:
Example
UPDATING ALL ROWS:- The update statement updates columns in the existing table’s rows with
new values .The SET clause indicates which column data should be modifying and the new values
that they should hold. The WHERE CLAUSE specifies which rows should be updated.
Otherwise all table rows are updated.
Example:
Update student set student marks = ‘10’ where student ID =1;
14. Alter Table
The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table.
Syntax:
Example:
You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all
the records would be deleted.
Syntax
The basic syntax of the DELETE query with the WHERE clause is as follows −
Example:
The DROP TABLE statement removes a table and its data permanently from the database.
17. Difference between Delete, Drop and Truncate commands
in Sql
The DELETE command deletes one or more existing records from the
table in the database. The DROP Command drops the complete table
from the database. The TRUNCATE Command deletes all the rows from
the existing table, leaving the row with the column names.
18. TO ILLUSTRATE RENAME COMMAND IN SQL
RENAMING TABLES: - Oracle allows renaming of tables. The rename operation is done
atomically, which means that no other thread can access any of the tables while the rename process
is running.
2.Entity Constraints: It states that the primary key value cannot be null.
Example:
3.Referential Constraint: A Referential Integrity constraints is specified between two
tables. In the referential integrity constraint, table refers to if a foreign key in the primary
key of table 2, every then value of the foreign must be available in table 2 0r must be null.
4.Key Constraint: key's are the entity set that is used to identify within its entity set
uniquely. An entity can have multiple keys, but out of which one key will be primary key.
The primary key will contain unique value in the relational table.
20. Aggregate functions in SQL
SQL is excellent at aggregating data the way we might in a pivot table in Excel. We will use
aggregate functions all the time, so it's important to get comfortable with them. The functions
themselves are the same ones you will find in Excel or any other analytics program. We'll cover them
individually in the next few lessons. Here's a quick preview: