Samp
Samp
Samp
show databases;
use sampledb;
show tables;
create table Student(
id int primary key auto_increment,
s_name varchar(50) not null,
age int not null default 18,
courseId int not null,
constraint fk_course foreign key (courseId) references course(courseid)
);
desc course;
desc employee;
insert into employee values (3001, 'Prithvi', 'Raj', 'Accountant', 1002, 'lsfjk',
curdate());
insert into employee values (3002, 'Kanchan', 'K', 'Developer', 1004, 'dfgk',
'2020-12-01');
insert into employee values (3003, 'Manoj', 'M', 'Accountant', 1002, 'sdfsdf',
'2020-10-20');
insert into employee values (3004, 'Nayan', 'T', 'Tester', 1001, 'ddes', '2020-09-
09');
select * from employee;
select now();
select curdate();
select concat('Pallavi', ' ', 'Prasad');
-- ------------------------------------------------------------------------------
use classicmodels;
select count(*) from customers;
select * from customers LIMIT 10; -- shows the top 10 records
select * from customers LIMIT 100, 5; -- shows 5 records starting from the 101th
select * from customers where country='USA' limit 10;
select customerNumber, customerName, concat(contactFirstName, ' ', contactLastName)
as 'Contact', creditLimit
from customers where country='Australia'
order by creditLimit desc
limit 5;
-- substring example
select substring('subsring examp', instr('subsring examp', 'r'), length('subsring
examp'));
-----------------------------------------------------------------------------------
----------------------------------------
create database sampledb;
show databases;
use sampledb;
show tables;
create table Student(
id int primary key auto_increment,
s_name varchar(50) not null,
age int not null default 18,
courseId int not null,
constraint fk_course foreign key (courseId) references course(courseid)
);
desc course;
desc employee;
insert into employee values (3001, 'Prithvi', 'Raj', 'Accountant', 1002, 'lsfjk',
curdate());
insert into employee values (3002, 'Kanchan', 'K', 'Developer', 1004, 'dfgk',
'2020-12-01');
insert into employee values (3003, 'Manoj', 'M', 'Accountant', 1002, 'sdfsdf',
'2020-10-20');
insert into employee values (3004, 'Nayan', 'T', 'Tester', 1001, 'ddes', '2020-09-
09');
select * from employee;
--
-----------------------------------------------------------------------------------
-----------
-- SELECT STATEMENTS------------------------------
--
-----------------------------------------------------------------------------------
-----
select * from student;
select courseid, s_name, age from student;
select courseid, s_name, age from student where courseid=100;
select courseid, s_name, age from student where age in (18, 19);
select courseid, s_name, age from student where age >=18 and age <= 19;
select courseid, s_name, age from student where age not between 18 and 19;
select now();
select curdate();
select concat('Pallavi', ' ', 'Prasad');