Tuesday, February 20, 2018

MySQL sSQL

use Sakila;
Select * from Actor;
/*this a comment*/
Select First_name, Last_name, title, release_year, rating
from Actor
Inner join film_Actor
on Actor.actor_id = Film_Actor.actor_id
inner join Film
on film.film_id=Film_Actor.film_id
Where first_name='Bette' and Last_name='Nicholson';

Insert into Actor(first_name, last_name, last_update)
Values('Chuck','Mannley', current_date());

Insert into Film_Actor(actor_id,Film_id,Last_update)
Values(201,1,current_timestamp());


Select First_name, Last_name, title, release_year, rating
from Actor
Inner join film_Actor
on Actor.actor_id = Film_Actor.actor_id
inner join Film
on film.film_id=Film_Actor.film_id
Where actor.actor_id=201;


Create table actorb
(
 actor_id int, 
    first_name varchar(45), 
    last_name varchar(45), 
    last_update timestamp

);
Insert into actorb(actor_id, first_name, last_name, last_update)
Select actor_id, first_name, last_name, last_update
From Actor;

Select * from Actorb;

Alter table Actorb
Add Constraint PK_Actorb_Id Primary Key (actor_id);

Update actorb
set last_name = 'Guinness',
first_name='Penny'
where actor_id=1;

update actorb
Set Last_name='Smith'
Where actor_id > 0;

Delete from actor
Where actor_id=201;

Delete from film_actor
where actor_id=201;

Start transaction ;

Update actorb
set First_name='john'
where actor_id > 0;

Select * from actorb;


rollback ;
commit;

Drop table actorb;

No comments:

Post a Comment