Created
February 4, 2020 10:21
-
-
Save MoatazAbdAlmageed/e86134ce492acf5a59fa69c070d05137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
drop database learn; | |
create database learn; | |
show databases; | |
use learn; | |
show tables; | |
-- #################### CREATE | |
CREATE TABLE users ( | |
id int PRIMARY KEY NOT NULL AUTO_INCREMENT, | |
first_name varchar(25) not null, | |
last_name varchar(25)not null, | |
salary decimal(5, 2) check (salary>100), | |
age int(3), | |
department varchar(25) DEFAULT 'front' | |
); | |
-- #################### describe | |
describe users; | |
-- #################### insert | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",70); | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",200); | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",250); | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",300); | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",400); | |
insert into users (first_name,last_name,salary) values ("moataz","mohammady",500); | |
insert into users (first_name,last_name,salary) values ("mohamed","mohammady",500); | |
insert into users (first_name,last_name,salary) values ("zaki","mohammady",500); | |
insert into users (first_name,last_name,salary) values ("zaki2","mohammady",500); | |
insert into users (first_name,last_name,salary) values ("zahraa","mohammady",500); | |
insert into users (first_name,last_name,salary) values ("mohammady","mohammady",500); | |
insert into users (first_name,last_name,salary , department) values ("moataz","mohammady",400 ,'back'); | |
insert into users (first_name,last_name,salary , department , age ) values ("moataz","mohammady",400 ,'back' , 30); | |
-- #################### select | |
select * from users ; | |
select * from users where id = 1; | |
select * from users where salary > 200; | |
select * from users where salary > 200 and salary < 500 ; | |
select * from users where department = 'back'; | |
-- https://www.w3schools.com/sql/sql_wildcards.asp | |
select * from users where first_name like 'za%'; | |
select * from users where first_name like '________y%'; | |
select * from users where first_name like '%y'; | |
select * from users where age is not null ; | |
select * from users where age is null order by salary ; | |
select * from users where age is null order by salary desc; | |
-- #################### delete | |
delete from users where first_name='zaki2'; | |
-- #################### update | |
update users set salary=900 where first_name="moataz"; | |
select * from users ; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment