T-SQL
Day 2
T-SQL History
T-SQL History
T-SQL History
➢ Developed in the early 1970 (SEQual)
➢ ANSI-SQL defined by the American National Standards
Institute
➢ Microsoft implementation is T-SQL, or Transact SQL
➢ Other implementations include PL/SQL and IBM’s SQL
Procedural Language.
Categories of T-SQL Statements
➢ DML – Data Manipulation Language
➢ DCL – Data Control Language
➢ DDL – Data Definition Language
➢ TCL - Transactional Control Language
➢ DQL - Data Query Language (Select)
Data types
A data type determines the type of data that can be stored in a
database column. The most commonly used data types are:
1. Alphanumeric: data types used to store characters,
numbers, special characters, or nearly any combination.
2. Numeric
3. Date and Time
Executing Queries
Executing queries occurs when in a query session by:
➢Selecting the Execute Icon
➢Pressing the F5 key
Note:
Select the Database Before Executing Query or write
Use Keyword + DB Name on top of the Query
Commenting T-SQL Code
• Comments are statements about the meaning of the code
• When used, there is no execution performed on the text
There are two ways to comment code using T-SQL:
• The use of a beginning /* and ending */ creates comments
/*
This is a comment
*/
• The double dash comments to the end of line
--This is a comment
Steps
Create new folder in any place in your device
Steps
Create new database.
Steps
11/10/2025 ERD Concepts
Steps
11/10/2025 ERD Concepts
Steps
11/10/2025 ERD Concepts
Steps
Create new table wizard
11/10/2025 ERD Concepts
Steps
Create new table wizard
11/10/2025 ERD Concepts
Steps
Set composite primary key
11/10/2025 ERD Concepts
Steps
Create work table
11/10/2025 ERD Concepts
Steps
Create work table
11/10/2025 ERD Concepts
Steps
Create foreign key
11/10/2025 ERD Concepts
Steps
Enter data in employee table
11/10/2025 ERD Concepts
Steps
Enter data in project table
11/10/2025 ERD Concepts
Steps
Enter data in work table
11/10/2025 ERD Concepts
Data Definition Language
Modifying Data in Tables
Create Table
Alter Table
Drop Table
Create Table
Syntax:
CREATE TABLE [table_name]
("column 1" "data_type",
"column 2" "data_type", ... )
Example
CREATE TABLE Employee
(ID int Primary Key,
FName char(50) Not Null,
LName char(50),
Address char(50),
Birth_Date date);
Create Table
Default value:
Drop Table
Syntax:
Drop Table “Table_Name”
Example
Drop Table Employee
Alter Table
Syntax:
ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name DROP column_name
Example
ALTER TABLE employee ADD City varchar(30)