-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_into_statements.sql
More file actions
32 lines (19 loc) · 878 Bytes
/
insert_into_statements.sql
File metadata and controls
32 lines (19 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use world;
show tables;
select * from city;
describe city;
create table newCity(ID int primary key auto_increment, Name CHAR(35) NOT NULL,
CountryCode CHAR(3) NOT NULL, District CHAR(20) NOT NULL, Population int NOT NULL DEFAULT 0 );
select * from newCity;
-- now inserting the city records into newCity
insert into newCity
select * from city; -- for copying all the data
-- for copying some data
create table newCity1(ID int primary key auto_increment, Name CHAR(35) NOT NULL, CountryCode CHAR(3) NOT NULL);
insert into newCity1
select id, name, countrycode from city;
select * from newCity1;
-- if we want to do some column when there are multiple column then
insert into newCity1(id, name)
select id, name from city; -- this can also be done
-- we can also use where clause means we can do anything with the select statement accordingly and then store the data