SQL
SQL
SQL
constraint - rules
not null - that filed must be filled
check - verify if all values statisfy the conditions
default - automatically assigns values if no value has been specified for that
field
create table student (id int not null, name varchar(20), primary key (id))
alter table student add primary key(id)
create table student (id int not null, name varchar(20) not null)
alter table student add constraint pk_stud primary key(id,name)
joins
inner join - select * from stud_table inner join teacher_table;
left outer join - select * from stud_table s left join teacher_table t on s.col =
t.col;
right outer join - select * from student s right join teacher t on s.col= t.col;
full outer join - select * from student s full join teacher t on s.col=t.col;
self join -
table - empp
e_id e_name m_id
1 a null
2 b 1
3 c 1
4 d 2
select e.e_name as "name" , m.e_naame as 'manager' from empp e left join empp m on
e.e_id = m.e_id
-----------------------------------------------------------------------------------
--------------
Query the two cities in STATION with the shortest and longest CITY names, as well
as their respective lengths (i.e.: number of characters in the name). If there is
more than one smallest or largest city, choose the one that comes first when
ordered alphabetically.
The STATION table is described as follows:
ans------------------->>>>>
select city,length(city) from station order by length(city) asc,city limit 1;
select city,length(city) from station order by length(city) desc, city limit 1;