Create Table
Create Table
To create DB tables from the wizard right click on tables and choose table then determine the column name and its
data type
Create Table:
1- To create table by SQL orders: Create Table Table_Name (column1 type1, column2 type2, column3 type3)
2- To set specific column to be primary key or unique: 1- on the table_name write click 2- choose design 3- go to
column name and click on it 4- go to key sign and click on it to set it primary key.
3- Or right click on the specific column name in the table and choose set primary key.
Insert Commands:
1- To insert values inside table column: Insert into Table (columns) values (values as table created)
2- We can insert values directly without writing table columns: insert into Table_Name values (value1,
value2, …)
Remove Commands:
1- We can remove all data inserted (all rows) from table by using this order: delete from Table_Name
2- We can remove specific row or rows from table by using this order: delete from Table_Name where
column_name = Specific_value
Update Commands:
1- To update all column of the table by one value: update table_name set column_name =’value’
2- To update specific column value in the Table: update table_name set column_name=’new value’ where ID=value
or ‘value’
3- To update more than one row values: update table_name set column_name1= value1 , column_name2 = value2 ,
column_name3 = value3 where ID=value
Select Statement:
1- Select * from table_name;
2- Select * from table_name where condition_column_name = ‘value’;
3- Select column_name from table_name;
4- Select column_name from table_name where condition_column_name=’value’;
5- Select column_name1, column_name2, column_name3 from table_name;
6- Select column_name1, column_name2, column_name3 from table_name where condition_column_name=’value’;
7- Select column_name1, column_name2, … from table_name where column_name_value > value;
8- Select column_name1, column_name2, … from table_name where column_name_value >= value;
9- Select column_name1, column_name2, … from table_name where column_name_value > value and < value;
10- Select column_name1, column_name2, … from table_name where column_name_value > value or < value;
11- Select column_name1, column_name2, … from table_name where column_name_value <> value; // not equal value
12- Select column_name1, column_name2, … from table_name where column_name_value != value; // not equal value
13- Select * from table_name where condition_column_name is null; //to select null columns
14- Select * from table_name where condition_column_name is not null; //to select all columns without null columns
15- Select * from table_name where condition_column_name in (‘ ’ , ’ ’ , ‘ ’) //to select from more than one value in the column
16- Select * from table_name where condition_column_name not in (‘ ’ , ’ ’ , ‘ ’) //to select from more than one value not in
column value
17- Select * from table_name where condition_column_name between (‘ ’ , ’ ’ , ‘ ’)
18- Select * from table_name where condition_column_name not between (‘ ’ , ’ ’ , ‘ ’)
19- Select * from employee_name where month(birth_date)= الشهرday(birth_date)= اليوم
a) Select using Inner Join
- Select first_name , last_name , email , order_id , order_date , store_id from sales.customer c join sales.order o
where c.customer_id = o.customer_id //join takes on and where
- Select first_name , last_name , email , order_id , order_date , store_id from sales.customer c , sales.order o where
c.customer_id = o.customer_id
Select first_name , last_name , email , order_id , order_date , store_id from sales.customer inner join sales.order
where
Sales.customer_id = sales.order_id