Skip to content

Commit 131b7cd

Browse files
committed
understanding insert into statements
1 parent b987404 commit 131b7cd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

insert_into_statements.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use world;
2+
3+
show tables;
4+
5+
select * from city;
6+
7+
describe city;
8+
9+
create table newCity(ID int primary key auto_increment, Name CHAR(35) NOT NULL,
10+
CountryCode CHAR(3) NOT NULL, District CHAR(20) NOT NULL, Population int NOT NULL DEFAULT 0 );
11+
12+
select * from newCity;
13+
14+
-- now inserting the city records into newCity
15+
insert into newCity
16+
select * from city; -- for copying all the data
17+
18+
19+
-- for copying some data
20+
create table newCity1(ID int primary key auto_increment, Name CHAR(35) NOT NULL, CountryCode CHAR(3) NOT NULL);
21+
22+
insert into newCity1
23+
select id, name, countrycode from city;
24+
25+
select * from newCity1;
26+
27+
-- if we want to do some column when there are multiple column then
28+
insert into newCity1(id, name)
29+
select id, name from city; -- this can also be done
30+
31+
32+
-- we can also use where clause means we can do anything with the select statement accordingly and then store the data

0 commit comments

Comments
 (0)