Basic SQL Ram Kumar About Me My Self Ram Kumar I have 15 Years of extensive knowledge in database and currently I am associated with Allscripts. Skill : Oracle Database 10g/11g/12c/19c/21c Oracle Forms and Reports 6i/10g/11g/12c Postgres 9.2/9.3/9.4/10/11 Java Spring MVC, Oracle ADF etc. Qualification : MCA Language : English & Hindi ☏ Mobile – +91-9220970607 ✉ Email – ram5393@gmail.com About Database/RDBMS/Table/Column What is different Type of Database ? What is SQL ? Course Outline What are the Type of SQL Commands ? What is Transactions ? What is Constraints ? What is View? Comments What is database? ▪ A database is an organized collection of data, so that it can be easily accessed and managed. ▪ You can organize data into tables, rows, columns it to make it easier to find relevant information. ▪ The main purpose of the database is to operate a large amount of information by storing, retrieving, and managing data. ▪ SQL or Structured Query Language is used to operate on the data stored in a database. About Database Type of Database SQL Conclusion What is RDBMS? ▪ RDBMS stands for Relational Database Management System. ▪ All modern database management systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL, and Microsoft Access are based on RDBMS. ▪ It is called Relational Database Management System (RDBMS) because it is based on the relational model introduced by E.F. Codd. ▪ Data is represented in terms of tuples (rows) in RDBMS. ▪ A relational database is the most commonly used database. It contains several tables, and each table has its primary key. About RDBMS Type of Database SQL Conclusion Overview of Tables in SQL ▪ Tables are the fundamental way to store data in a relational database management system. It contains a header row at the top of the table, which gives the list of column names, followed by rows that contain data. Below is the Employee Table ▪ In simple terms, it’s a collection of related data held in a table format. Fields/Column in SQL ▪ Fields are basically columns in a table with specific information about the data. Records/Data in SQL ▪ A record is basically an individual entry that exists in a table. Records give complete information about a single entry or entity About Table Type of Database SQL Conclusion What is Normalization ▪ Normalization is a database design technique that reduces data redundancy and eliminates undesirable characteristics like Insertion, Update and Deletion Anomalies. ▪ Normalization rules divides larger tables into smaller tables and links them using relationships. ▪ The purpose of Normalization in SQL is to eliminate redundant (repetitive) data and ensure data is stored logically. Why SQL Type of Database SQL Conclusion Tools to Connect Database ▪ SQL*Plus is a software tool with an interface into which you can type SQL and SQL*Plus commands and monitor their execution. This is inbuild no need any external installation. ▪ SQL Developer - Oracle SQL Developer is a free, integrated development environment that simplifies the development and management of Oracle Database.Its GUI Based so working with it is simple compared to SQL Plus. SQL Tools Type of Database SQL Conclusion Why should you learn SQL? ▪ SQL is an easy-to-learn language specifically designed to work with databases. ▪ There is a growing demand for professionals who can handle databases like Software Engineer ,Business Analyst ,Data Scientist etc. ▪ Almost every big company is using SQL. It is widely used in various sectors like ticket booking, banking, social media platforms, data sharing, eCommerce etc. ▪ It is used in data systems such as MySQL, PostgreSQL, Oracle and many others. Why SQL Type of Database SQL Conclusion Type of Database SQL No SQL. SQL is a relational database management system. The query language used in this database system is a structured query language. The schema of SQL databases is predefined, fixed, and static. The database type of SQL is in the form of tables, i.e., in the form of rows and columns. SQLite, SQL Server, Oracle, PostgreSQL, and MySQL are examples of SQL database systems. No-SQL is a non-relational database management system. The query language used in the No-SQL database systems is a non-declarative query language. The schema of No-SQL databases is a dynamic schema for unstructured data. The database type of No-SQL is in the form of documents, key-value, and graphs. Redis, MongoDB, Hbase, BigTable are examples of NoSQL database systems. Why SQL Type of Database SQL Conclusion What is SQL ? SQL is Structured Query Language which help to manage databases. it helps Database Creation, Database Deletion, Fetching Data Rows, Modifying & Deleting Data rows, etc. It is also the standard language used in the Relational Database Systems. Various Relational Database Systems like MySQL, Sybase, Oracle, MS Access, Postgres, Infomix, SQL Server, etc., have SQL as their base language. Why SQL Type of Database SQL Conclusion Data Type Data Type define the value that column is going to store. Oracle supplies the following built-in datatypes: ▪ CHARACTER Datatypes CHAR - > Fixed for every row in the table maximum size is 2000 bytes per row, Varchar2 -> Variable for each row, up to 4000 bytes per row. Long -> Maximum size of 2GB. ▪ NUMBER Datatype Number -> Storing numeric value Number(Precision,Scale) ▪ DATE Datatype Date -> Storing Date Field ▪ Binary Datatype BLOB -> Store up to 4GB of binary data. Stores unstructured binary large objects. Ex Image, Video & Audio CLOB -> Store up to 4GB of character data. Stores single-byte and multi-byte character data. Ex- XML data BFILE -> Maximum file size of 4GB. Unlike BLOB and CLOB types, BFILE data type does not store the binary file itself but stores the address (file system path) of the file. Therefore, it is suitable for storing large binary files such as images, audios, videos, etc., to reduce the storage burden on the database server. Why SQL Type of Database SQL Conclusion What is Transaction ? A transaction is the logical work unit that performs a single activity or multiple activities in a database. Transactions may consist of a single read, write, delete, or update operations or a combination of these. COMMIT or ROLLBACK TRANSACTION Apply data changing to the database or Erase data changing to the database Why SQL Type of Database Transaction Conclusion DDL DML SQL Command DQL TCL DCL Why SQL Type of Database Data Definition Language DDL is used to define the structure or schema of the database. Some of the DDL commands are as follows : 1. Create: to create objects in the database 2. Alter: alters the structure of the database 3. Rename: rename an object 4. Truncate: deletes all the data stored in a table 5. Drop: delete objects from the database DDL Conclusion DDL SQL Command DML DML is used for managing data contained in the schema objects. DQL Some of the DML commands are as follows : TCL DCL Why SQL Data Manipulation Language Type of Database 1. Insert: used to insert data in the database 2. Update: used to modify the existing data in the database 3. Delete: used to delete all/Limited records in the database. 4. Merge: used to merge two or more tables or rows. DML Conclusion DDL DML SQL Command DQL TCL DCL Why SQL Type of Database Data Query Language DQL is also known as the Data Query language. It is used to retrieve the data stored in the database created by us and the data we store in the database. Syntax: Select * from table Name ; After executing this command, we can view all the columns and all the data stored in the table. Example: Select * from employee : helps in viewing all the data i.e., all rows and columns. DQL Conclusion Transaction Control Language DDL DML SQL Command Why SQL DQL TCL also know as Transaction Control Language .TCL commands are used to handle transactions in the database. These are used to manage and track the changes made by DML statements , these can be grouped together into logical transactions. Example: 1. Commit: used to permanently save any transaction into the database. TCL 2. Rollback: used to restore the database to the last committed state and is also used with the Savepoint command to move over to any saved state in a transaction. DCL 3. Savepoint: It is used to temporarily store a transaction so that we can move to the point we need whenever desired. Type of Database TCL Conclusion SQL Command DDL Data Control Language DML DCL also know as Data Control Language which includes commands such as GRANT and mostly concerned with rights, permissions and other controls of the database system. DQL TCL DCL Why SQL Type of Database While using DCL commands, we need to be cautious as some database’s don’t allow rollback command on the DCL command. One such example is the Oracle database . Example : 1. Grant: allow users access privileges to the database. 2. Revoke: withdraw users access privileges given by using the GRANT command. DCL Conclusion Create User Use the CREATE USER statement to create and configure a database user, which is an account through which you can log in to the database, and to establish the means by which Oracle Database permits access by the user. Prerequisites You must have the CREATE USER privileges. Syntax :- CREATE USER SCOTT IDENTIFIED BY tiger; select * from all_users; GRANT ALL PRIVILEGES TO HR; DROP USER SCOTTNEW CASCADE; Why SQL Type of Database Constraints Conclusion DCL(Grant / Revoke) Grant is used to grant privileges on tables, view, procedure to other users or roles. ExSuppose you own emp table. Now you want to grant select and insert privilege on this table to another user “HR”. Grant select, insert on emp to HR; Suppose you want to grant all privileges(Select ,Insert ,Update ,Delete ,Alter ) on emp table to HR. Then Grant all on emp to HR; Revoke is used to revoke privileges already granted to other users. Example to revoke select and insert privilege you have granted to HR then give the following statement. Revoke select, insert on emp from HR; To revoke All privileges on emp granted to HR give the following command. Revoke ALL on emp from HR; Why SQL Type of Database Constraints Conclusion Information About Privileges To see which table privileges are granted by you to other users. Select * from user_tab_privs_made; To see which table privileges are granted to you by other users Select * from user_tab_privs_recd; To see which column level privileges are granted by you to other users. Select * from user_col_privs_made; To see which column level privileges are granted to you by other users Select * from user_col_privs_recd; Why SQL Type of Database Constraints Conclusion What is Constraints ? Constraints are the rules that we can apply on the type of data in a table. That is, we can specify the limit on the type of data that can be stored in a particular column in a table using constraints. List of constraints are NOT NULL- This constraint tells that we cannot store a null value in a column. UNIQUE - This constraint when specified with a column, tells that all the values in the column must be unique. PRIMARY KEY - A primary key is a field which can uniquely identify each row in a table. FOREIGN KEY - A Foreign key is a field which can uniquely identify each row in another table. CHECK - This constraint helps to validate the values of a column to meet a particular condition. DEFAULT - This constraint specifies a default value for the column when no value is specified by the user. Why SQL Type of Database Constraints Conclusion What is View ? A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. You can add SQL statements and functions to a view and present the data as if the data were coming from one single table. Example CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition; A view always shows up-to-date data! The database engine recreates the view, every time a user queries it. Why SQL Type of Database View Conclusion SQL Comments Single-line comments :- Comments starting and ending in a single line are considered single-line comments. A line starting with ‘–‘ is a comment and will not be executed. Syntax :- -- single line comment Select * from Employee. – This Query will fetch data from Employee table. Multi-line comments :- Comments starting in one line and ending in different lines are considered as multiline comments. A line starting with ‘/*’ is considered as starting point of the comment and is terminated when ‘*/’ is encountered. Syntax:- Select * from employee. /* This will get the data from employee table. */ Why SQL Type of Database Comment Conclusion Here is what we learned ▪ SQL ▪ Type of Database Summary ▪ SQL Command (DDL,DML,DQL,DCL) ▪ Transaction ▪ Constraints ▪ View ▪ Comments Conclusion