SQL GreatthoughtsIT 8april24
SQL GreatthoughtsIT 8april24
The first two components of information systems: Hardware and Software. Without data,
hardware and software are not very useful. Data is the third component of an information
system.
Data are the raw bits and pieces of information with no context. If I told you, “15, 23, 14,
85,” you would not have learned anything.
By itself, data is not that useful. To be useful, it needs to be given context. Returning to the
example above, if I told you that “15, 23, 14, and 85″ are the numbers of students that had
registered for upcoming classes, that would be information.
Data can be quantitative or qualitative. Quantitative data is numeric, the result of a
measurement, count, or some other mathematical calculation. Qualitative data is
descriptive. “Ruby Red,” the color of a 2013 Ford Focus, is an example of qualitative data.
Once we have put data into context, aggregated and analyzed it. We can use that to
make decisions. Once we consume of this information produces knowledge. This
knowledge can be used to make decisions, set policies etc.,
What is Data Base
The goal of many information systems is to transform data into information in order to
generate knowledge that can be used for decision making. In order to do this, the system
must be able to take data, put the data into context, and provide tools for aggregation
and analysis. A database is designed for just such a purpose.
The database stores the data in well-structured format/in organized manner. We can derive
information from a well-structured data.
A database is a place to store information permanently. It can store the simplest data, such
as a list of people as well as the most complex data.
A database is a systematic collection of data. They support electronic storage and
manipulation of data. Databases make data management easy.
The database's primary goal is to store a huge amount of data.
Example: An online telephone directory uses a database to store data of people, phone
numbers, and other contact details. Your electricity service provider uses a database to
manage billing, client-related issues, handle fault data, etc
Why use Data Base
Graph databases: A graph-oriented database uses graph theory to store, map, and query relationships. These kinds of
computers databases are mostly used for analyzing interconnections. For example, an organization can use a graph database to
mine data about customers from social media.
Personal database: A personal database is used to store data stored on personal computers that are smaller and easily
manageable. The data is mostly used by the same department of the company and is accessed by a small group of people.
What is SQL - https://dev.mysql.com/downloads/installer/
In dbms relationship between two tables or files are In Rdbms relationship between two tables or files can be
maintained programmatically specified at the time of table creation.
Dbms does not support client server architecture. Rdbms supports client server architecture.
Dbms does not support distributed architecture. Rdbms support distributed architecture.
Dbms may satisfy less than 7 rules of Dr. e.f codd Rdbms usually satisfy more than 7 to 8 rules of Dr. e.f codd.
Examples of DBMS are file systems, xml etc. Example of RDBMS are mysql, postgre, sql server, oracle etc.
Data Base Schema
It’s the database designers who design the schema to help programmers understand the database and make it useful.
A database schema is a structure that represents the logical storage of the data in a database.
A database schema is the logical representation of a database, which shows how the data is stored logically in the entire
database.
A database schema contains schema objects that may include tables, fields, packages, views, relationships, primary key,
foreign key etc.,
The schema does not physically contain the data itself; instead, it gives information about the shape of data and how it can be
related to other tables or models.
Physical Database Schema − This schema pertains to the actual storage of data and its form of storage like files, indices,
etc. It defines how the data will be stored in a secondary storage.
Logical Database Schema − This schema defines all the logical constraints that need to be applied on the data stored. It
defines tables, views, and integrity constraints.
SQL Commands
Integer INTEGER
Smallint SMALLINT
Numeric NUMERIC(P,S)
Real REAL
Decimal DECIMAL(P,S)
Float FLOAT(P)
Character CHAR(X)
Date Date
Time TIME
Table Commands (Create/Drop/Alter/Truncate)
CREATE TABLE Students (
StdID int ,
StudentName varchar(255) ,
Branch varchar(255),
Specialization varchar(255),
Gender varchar(255),
Age int
);
The ROLLBACK statement lets a user undo all the alterations and changes that occurred
on the current transaction after the last COMMIT.
Ex: Rollback;
Savepoint is a command in SQL that is used with the rollback command. Consider you
are making a very long table, and you want to roll back only to a certain position in a
table then; this can be achieved using the savepoint
START TRANSACTION;
SAVEPOINT ini
Constraints
ORDER BY :- Used this command to display the data of a column in particular order
ASC for Ascending order
DESC for Descending order
GROUP BY :- GROUP BY clause is used to collect data across multiple records and group the results by one or
more columns.
HAVING :- The HAVING clause is used to apply a filter on the result of GROUP BY based on the specified
condition.
The GROUP BY and HAVING clauses of Aggregate Functions are used more often with SELECT statements in
SQL queries. Generally used in reports of large data.
Table Select:
INSERT INTO Employee VALUES (1, 'Rachit', 'M', 50000, 'Engineering', '6 year')
INSERT INTO Employee VALUES (2, 'Shobit', 'M', 37000, 'HR', '3 year')
INSERT INTO Employee VALUES (3, 'Isha', 'F', 56000, 'Sales', '7 year')
INSERT INTO Employee VALUES (4, 'Devi', 'F', 43000, 'Management', '4 year')
INSERT INTO Employee VALUES (5, 'Akhil', 'M', 90000, 'Engineering', '15 year')
The join clause allows us to retrieve data from two or more related tables into a meaningful result set.
We can join the table using a SELECT statement and a join condition.
It indicates how SQL can use data from one table to select rows from another table.
In general, tables are related to each other using foreign key constraints.
INNER JOIN
SELF JOIN
CROSS JOIN
OUTER JOIN
INNER JOIN
This JOIN returns all records from multiple tables that satisfy the specified join condition.
It is the simple and most popular form of join and assumes as a default join.
If we omit the INNER keyword with the JOIN query, we will get the same output.
SELF JOIN :- It means that each table row is combined with itself and with every other table row.
The SELF JOIN can be thought of as a JOIN of two copies of the same tables.
We can do this with the help of table name aliases to assign a specific name to each table's instance.
The table aliases enable us to use the table's temporary name that we are going to use in the query.
It's a useful way to extract hierarchical data and comparing rows inside a single table.
OUTER JOIN
OUTER JOIN in SQL Server returns all records from both tables that satisfy the join condition. In other words, this join will not return only the
matching record but also return all unmatched rows from one or both tables.