The document provides an introduction to SQL, explaining its purpose as a standard query language for managing relational databases using SQL Server Management Studio. It covers various data types, constraints, and SQL commands including DDL, DML, and DQL, detailing their functions such as creating, altering, and deleting tables, as well as inserting, updating, and querying data. Additionally, it discusses operators and clauses used in SQL for data retrieval and manipulation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views18 pages
Day 4 SQL
The document provides an introduction to SQL, explaining its purpose as a standard query language for managing relational databases using SQL Server Management Studio. It covers various data types, constraints, and SQL commands including DDL, DML, and DQL, detailing their functions such as creating, altering, and deleting tables, as well as inserting, updating, and querying data. Additionally, it discusses operators and clauses used in SQL for data retrieval and manipulation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18
DAY 4
Introduction to SQL What is SQL?
SQL stands for Standard Query Language.
SQL language is used to Store, manipulate and retrieve the data stored in the Relational Database System. We are using SQL Server Management Studio (SSMS) as our Relational Database System. Basically, the SQL Server acts as the platform to store databases and SQL is the standard language used in the platform to perform operations on those databases. Datatypes in MS SQL
int – stores number up to 4 bytes.
bigint – stores numbers up to 8 bytes. char – stores string data type and has a fixed width. varchar() – stores string data type but has a variable width which can be predefined. nchar() – stores multilanguage strings with predefined values. date – stores only the date part but no time. (YYYY-MM-DD) datetime – stores the date as well as time. (YYYY-MM-DD) Constraints in MSSQL
These constraints are applied on columns while creating a table
NOT NULL Constraint – Column value cannot be null
Unique Constraint – All values in a column have to unique, can take null values PRIMARY KEY – Unique identifier of a table, has to be unique and cannot be null IDENTITY(start,gap) – To auto-increment a column, used with Primary Key FOREIGN KEY – Links one table with another CHECK CONSTRAINT – to give user defined conditions to a column entry SQL Commands
• DDL – Data Definition
Language • DML – Data Manipulation Language • DCL – Data Control Language • TCL – Transaction Control Language • DQL – Data Query Language DDL : Create command
• To create a database • To create a table
DDL : Alter command
• To add a column, to • To remove a column,
an existing table form an existing table DDL : Drop command
To drop a table – Delete the
entire table including its data and headers
Difference between Drop, Delete and Truncate:
Drop – Deletes the entire table and its existence. Truncate – Deletes all the records of the table but keeps the headers like the column names. Delete – Delete enables the user to delete specific rows from a table using conditions. DML : Insert command
To insert values into an
existing table DML : Update command
• To update an entire • To update a specific row of a
column column using ‘where’ clause DML : Delete command
• To delete entire table • To delete entire table
except the column names except the column names DQL : Select command ‘Select’ is used to retrieve data from the table
• To retrieve entire • To retrieve specific • To retrieve ‘distinct’ rows
data from the table column from the table of a column from the table DQL : Select with ‘Where’ clause • To retrieve data from the table • To retrieve data from the using a specific condition table using two or more conditions DQL : Select with ‘In’ and ‘between’ operators
• To retrieve data from the • To retrieve data from the
table using ‘In’ operator table using ‘Between’ operator DQL : Select with ‘Like’ operator ‘Like’ operator is used for pattern matching with String values. Two wildcard characters are used mainly, ‘%’ and ‘_’ ‘ %’ – matches any sequence of character ‘_’ – matches any single character
• ‘Like’ operator using ‘%’ • ‘Like’ operator using ‘_’ character
character DQL : Select with ‘Order by’ clause • To retrieve data in an • To retrieve data in ascending order based on descending order based a column on a column DQL : Select with ‘Group by’ clause Group by clause is used to combine rows with similar data. There must be an aggregate function in the Select statement when Group By clause is used.
Grouping the data based on country
and counting the number of employee from each country Thank you!