SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE DATABASE school; USE school; SHOW TABLES from school; create table students (id integer, full_name varchar(30), birth_date date); select * from students; insert into students (id, full_name, birth_date) values(1, 'Jan Kowalski', '2010-10-15'); insert into students values (2, 'Kamil Nowak', '2010-04-21'); SET SQL_SAFE_UPDATES = 0; -- Polecenie SET SQL_SAFE_UPDATES = 0; w MySQL wyłącza tryb bezpiecznych aktualizacji (SQL_SAFE_UPDATES), -- który ogranicza możliwość wykonywania pewnych zapytań UPDATE i DELETE bez warunku WHERE. alter table students add column born_city varchar(40); update students set born_city = 'Rzeszów' where id = 2; insert into students (full_name, birth_date) values ('Mariusz Krawiec', '2010-05-06'); select * from students; alter table students add primary key (id); delete from students where id is null; alter table students drop primary key; alter table students modify column id integer primary key auto_increment; insert into students (full_name, birth_date, born_city) values ('Mariusz Krawiec', '2010-11-12', 'Rzeszów'); insert into students (full_name, birth_date, born_city) values ('Michał Wójcik', '2010-01-05', 'Tarnów'); insert into students (full_name, birth_date, born_city) values ('Katarzyna Zielińska', '2011-12-14', 'Dębica'); insert into students (full_name, birth_date) values ('Damian Lewandowski', '2010-11-15'); alter table students add column first_name varchar(20) after id; alter table students add column last_name varchar(20) after first_name; alter table students drop column first_name; alter table students drop column last_name; update students set first_name = 'Jan', last_name = 'Kowalski' where id = 1; select * from students; update students set first_name = 'Kamil', last_name = 'Nowak' where id = 2; update students set first_name = 'Mariusz', last_name = 'Krawiec' where id = 3; update students set first_name = 'Michał', last_name = 'Wójcik' where id = 4; update students set first_name = 'Michał', last_name = 'Wójcik' where id = 4; update students set first_name = 'Mariusz', last_name = 'Krawiec' where id = 5; update students set first_name = 'Katarzyna', last_name = 'Zielińska' where id = 6; update students set first_name = 'Damian', last_name = 'Lewandowski' where id = 7; alter table students drop column full_name; select distinct born_city from students where born_city is not null; -- DISTINCT eliminuje duplikaty, czyli zapewnia, że wynikiem zapytania będą unikalne wartości. Innymi słowy, -- jeśli w kolumnie born_city są powtarzające się miasta, to w wyniku zapytania każde miasto pojawi się tylko raz. CREATE TABLE Osoby ( Id INTEGER PRIMARY KEY, Imię VARCHAR(20), Nazwisko VARCHAR (35), Rok_urodzenia YEAR, Miejsce_urodzenia VARCHAR(35) ); INSERT INTO Osoby VALUES (1, 'Adam', 'Kowalski', 1964, 'Bydgoszcz'), (2, 'Adam', 'Nowak', 1972, 'Szczecin'), (3, 'Andrzej', 'Kowalski', 1986, 'Nidzica'), (4, 'Arkadiusz', 'Malinowski', 1986, 'Kielce'), (5, 'Andrzej', 'Malinowski', 1989, 'Kielce'), (6, 'Krzysztof', 'Nowicki', 1986, 'Bydgoszcz'), (7, 'Kacper', 'Adamczyk', 1971, 'Kielce'), (8, 'Kamil', 'Andrzejczak', 1971, 'Radom'), (9, 'Krzysztof', 'Arkuszewski', 1989, 'Szczecin'), (10, 'Kamil', 'Borowski', 1976, 'Skierniewice'); /* 1. Zmień miejsce urodzenia dla wszystkich Malinowskich na Warszawa 2. Dla osoby o id = 9 zmień rok urodzenia na 2000; 3. Dla wszystkich osób których imię zaczyna się na K oraz urodziły się po 1980 roku zmień nazwisko na Nowak 4. Dla wszystkich Szczecinian, zmień datę urodzenia na 2050 oraz nazwisko na Kowalski 5. Usuń wszystkie osoby urodzone po 2000 roku (włącznie) 6. Usuń wszystkie osoby których imię zaczyna się na literę K i urodziły się w Warszawie 7. Usuń zawartość tabeli. 8. Usuń tabelę */ select * from osoby; update osoby set Miejsce_urodzenia = 'Warszawa' where Nazwisko = 'Malinowski'; update osoby set Rok_urodzenia = '2000' where id = 9; update osoby set Nazwisko = 'Nowak' where Rok_urodzenia > '1980' and Imię like 'K%'; update osoby set Rok_urodzenia = '2050', Nazwisko = 'Kowalski' where Miejsce_urodzenia = 'Szczecin'; delete from osoby where Rok_urodzenia >= 2000; delete from osoby where Miejsce_urodzenia = 'Warszawa' and Imię like 'K%'; delete from osoby; truncate osoby; drop table osoby;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear