Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is.

Similar presentations


Presentation on theme: "SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is."— Presentation transcript:

1 SQL

2 Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database. SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix,and SQL Server use SQL as standard database language. Also, they are using different platforms, such as:  MS SQL Server using T-SQL,  Oracle using PL/SQL,  MS Access version of SQL is called JET SQL (native format) etc.

3 Why SQL? Allows users to access data in relational database management systems. Allows users to describe the data. Allows users to define the data in database and manipulate that data. Allows to embed within other languages using SQL modules, libraries & pre-compilers. Allows users to create and drop databases and tables. Allows users to create view, stored procedure, functions in a database. Allows users to set permissions on tables, procedures and views

4 SQL Commands The standard SQL commands to interact with relational databases are DDL -Data Definition Language: CommandDescription CREATECreates a new table, a view of a table, or other object in database ALTERModifies an existing database object, such as a table. DROPDeletes an entire table, a view of a table or other object in the database

5 CommandDescription INSERTCreates a record UPDATEModify a record DELETEDelete a record or records DML -Data Manipulation Language DCL -Data Control Language CommandDescription GRANTGives a privilege to user REVOKETakes back privileges granted from user

6 DQL -Data Query Language SELECT- Retrieves certain records from one or more tables CommandDescription COMMITEnds the transaction and permanently makes all the changes during transaction. ROLLBACKEnds the transaction but undoes all the changes made during the transaction. TCL- Transaction Control Language.

7 SQL Constraints Constraints are the rules enforced on data columns on table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database. Following are commonly used constraints available in SQL: NOT NULL Constraint: Ensures that a column cannot have NULL value. DEFAULT Constraint: Provides a default value for a column when none is specified. UNIQUE Constraint: Ensures that all values in a column are different. PRIMARY Key: Uniquely identified each rows/records in a database table. FOREIGN Key: Uniquely identified a rows/records in any another database table. CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions.

8 SQL SYNTAX CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ….columnN datatype, PRIMARY KEY( one or more columns )); Create Table Using another Table CREATE TABLE NEW_TABLE_NAME AS SELECT [ column1, column2...columnN ] FROM EXISTING_TABLE_NAME [ WHERE ] INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN); Populate table using another table: INSERT INTO first_table_name [(column1, column2,... columnN SELECT column1, column2,...columnN FROM Second_table [WHERE Condition]; DROP TABLE table_name; Delete records from the table. DELETE FROM table_name ; OR DELETE FROM table_name WHERE [condition]; UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition];

9 Viewing Data in the Tables Select * from Tablename; Filtering Table Data Selected columns and all rows Selected rows and all columns Selected columns and selected rows. SELECT column1, column2, columnN FROM table_name WHERE [condition]

10 SQL Operators An operator is a reserved word or a character used primarily in an SQL statement's. Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement. Arithmetic operators Comparison operators Logical operators

11 SQL Arithmetic Operators OperatorDescription +Addition -Subtraction *Multiplication /Division %Modulus SQL Comparison Operators = != <> < > >=,<=

12 SQL Logical Operators AND OR NOT SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN]; SELECT column1, column2, columnN FROM table_name WHERE [condition1] OR [condition2]...OR [conditionN]

13 The LIKE operator LIKE is used to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with the LIKE operator: The percent sign (%) The underscore (_) SELECT * FROM Products WHERE PName LIKE ‘%gizmo%’ SELECT FROM table_name WHERE column LIKE 'XXXX%' or SELECT FROM table_name WHERE column LIKE '%XXXX%' or SELECT FROM table_name WHERE column LIKE 'XXXX_' or SELECT FROM table_name WHERE column LIKE '_XXXX' or SELECT FROM table_name WHERE column LIKE '_XXXX_'

14 Order BY SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2,.. columnN] [ASC | DESC]; Group BY SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 Distinct SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]


Download ppt "SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is."

Similar presentations


Ads by Google