DB - Day2
Categories of Microsoft Transact-SQL
Data Definition Language
Data Manipulation Language
Data Query Language
Data Query Language
Transact Control Language
Meta Data And structure
Data
Sequrity and permisions
Display
Execution
-------------------------
--------------------------
-----------------------
-------------------
-------------------------
Create Table
Insert
grant
Select +
begin transaction
Create function
update
deny
Join
Commit
create view
delete
revoke
subqueries
rollback
alter drop
Merge
union
select into
grouping
___
## DDL - Create queries
Create Database
```sql
CREATE DATABASE ITItest
```
Delete structure and data of database
```sql
DROP DATABASE ITItest
```
Backup database
``` sql
BACKUP DATABASE ITItest
FROM DISK ='D:\ITI.bak'
```
restore a backup of database
``` sql
RESTORE DATABASE ITItest
FROM DISK ='D:\ITI.bak'
```
Creating table
```SQL
USE ITItest
CREATE TABLE employee(
eid int PRIMARY KEY,
ename VARCHAR(20) NOT NULL,
eadd VARCHAR(20) DEFAULT 'cairo',
hiredate DATE DEFAULT GETDATE(),--built in function
salary INT DEFAULT 5000,
age INT,
dnum INT
)
```
Editing table to add column
```sql
ALTER TABLE employee ADD overtime INT
```
Editing column datatype in table
```sql
ALTER TABLE employee ALTER COLUMN overtime BIGINT
```
Deleting column from table
```sql
ALTER TABLE employee DROP COLUMN overtime
```
Delete data and structure
```sql
DROP TABLE employee
```
rename table
DML Query
Inserting data the values you don't enter must accept null or have default values otherwise it will give you Error
Inserting data to specific columns
Editing data based on condition
Editing the salary column to add 500 to each value
Delete only data but structure of table exists
DQL
Display all columns and rows from student table
displaying all columns but specific rows based on where clause
Displaying Specific columns and specific rows
Ordering data
Distinct : Order and remove redundant values
Displaying any student with a fname value
Displaying any student with a NULL fname
Display any student from cairo or alex
Display any student from cairo or alex or aswan
Display Any Student in department 10 or 30
Display any student with age in range 20 to 40
Last updated