0% found this document useful (0 votes)
2 views

sql copy

The document contains a series of SQL commands for creating, modifying, and managing databases and tables related to a course on Java. It includes operations such as creating databases, inserting and selecting data, altering tables, and performing various types of joins. Additionally, it demonstrates the use of multiple databases including 'meri', 'ecomm', and 'petstore'.

Uploaded by

merishavic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

sql copy

The document contains a series of SQL commands for creating, modifying, and managing databases and tables related to a course on Java. It includes operations such as creating databases, inserting and selecting data, altering tables, and performing various types of joins. Additionally, it demonstrates the use of multiple databases including 'meri', 'ecomm', and 'petstore'.

Uploaded by

merishavic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

create database javacourse;

drop database javacourse;


show databases;
show tables;
-- -- -- describe user;
use meri;
create table student(id int primary key auto_increment,username varchar(20),place
varchar(20));
select * from student;
insert into student values(null,'merisha','chennai');
insert into student(username,place) values('maha','chennai');
use student;
select * from student;
alter table student drop column gender;
insert into student values(null,'sanjai','ch'),(null,'sakthivel','chennai'),
(null,'david','ch');
alter table student add gender varchar(20);
update student set place='ariyalur' where id=5;
delete from student where id=2;

desc student;
alter table student modify place varchar(25);
alter table student rename to students;
show tables;
select * from students;
select * from students where place='chennai';
select username from students where place='chennai';
select distinct place from students where place='chennai';
select count(place) from students;
select count(distinct place) from students;
select * from students order by username;
select * from students where username='maha' and place='chennai';
select * from students where username='maha' or place='ch';
truncate students;
drop table students;
select * from students;
drop table students;
show tables;
-- -- -- drop database user;
-- -- --
use ecomm;
select * from users;
create table users(user_id int primary key,username varchar(20),city varchar(20));
CREATE TABLE orders (
order_no INT PRIMARY KEY,
user_id INT REFERENCES users(user_id),
product_id INT REFERENCES books(product_id)
);

INSERT INTO users VALUES (1, 'merisha', 'chennai');


INSERT INTO users VALUES (2, 'gra', 'arak');
INSERT INTO users VALUES (3, 'jen', 'pf');
insert into users values (1, 'merisha', 'chennai'), (2, 'gra', 'arak');
INSERT INTO orders (order_no, user_id, product_id)
VALUES (97, 1, 456);
INSERT INTO orders (order_no, user_id, product_id)
VALUES (76, 2, 27);
INSERT INTO orders (order_no, user_id, product_id)
VALUES (80, 3, 109);

-- use world;
-- select * from users cross join orders;

-- SELECT *
-- FROM users INNER JOIN orders
-- ON users.user_id = orders.user_id;

-- SELECT *
-- FROM users LEFT JOIN orders
-- ON users.user_id = orders.user_id;

-- SELECT *
-- FROM users RIGHT JOIN orders
-- ON users.user_id = orders.user_id;

use student;
create table science(sid int primary key auto_increment,name varchar(25));
create table maths(mid int primary key auto_increment,name varchar(25));
insert into science(name) values('maha'),('sanjai'),('david'),('sakthivel'),
('kirubakaran');
select * from science;
insert into maths(name) values('maha'),('jai'),('jen'),('sakthivel'),('gracy');
select * from maths;

select * from science as s right join maths as m on s.name = m.name;


select * from science as s left join maths as m on s.name = m.name;

select * from science as s inner join maths as m on s.name = m.name;


drop table football;
use student;
use petstore;
use meri;
select * from user;
create database petstore;

use student;
select * from user;

use meri;
select * from user;

You might also like