create table table_name(attr_1 data_type,
attr_2 data_type
...
...
);
create table table_name(attr_1 data_type primary key,
attr_2 data_type not null,
attr_3 datay_type default 'default_value',
attr_4 data_type check(attr_4 < 100)
);
select constraint_name, constraint_type from user_constraints where table_name="OUR_TABLE";
create table doctor(docid int primary key,
docname char(40) not null
);
create table appt(apptdate timestamp,
doctorid int refereces doctor(docid),
patid int references patient(patid),
primary key(appdate, doctorid, patid)
);
create table visit(visitid int,
vdt timestamp,
docid int,
patid int,
foreign key(vdt, docid, patid) refereces appt(appdate, doctorid, patid));
desc table_name;
drop table table_name;
insert into table_name values(null, default, ...);
select * from table_name;
select attr_1||attr_2||attr_3.. from table_name;
select trim(attr_1) from table_name;
delete from table_name
delete from table_name where conditions;
update table_name set attr=new_value, attr_2=new_value where attr=old_value
select distinct field/*/function/expression
from table_name/subquery
where condition_on_record_level
group by fieldnames/expression/function
having condition_on_grp/condition_on_aggregate_function
order by fieldname/expression/function
select upper(patname),
lower(patname),
trim(patname),
rtrim(patname), //trim empty space from right
ltrim(patname),
initcap(patname), // First letter capital
substr(patname,2,2) // From 2nd pos display 2 char
from patient where patid = 3;
select stdno, to_char(birtdate, 'dd') from students2021;
select stdno, to_char(birtdate, 'mm') from students2021;
select stdno, to_char(birtdate, 'yy') from students2021;
select stdno, to_char(birtdate, 'yy-mm-dd') from students2021;
select stdno, to_char(birtdate, 'month') from students2021;
select stdno, to_char(birtdate, 'dd month yyyy') from students2021;
select stdno, to_char(birtdate, 'ddth month yyyy') from students2021;
select stdno, to_char(birtdate, 'ddsp') from students2021; // spelling(sp)
select * from patients where patid in (list...);
select * from patients where patid in (select patid from appt);
two wildcards
select patname from patient where patname like 'x%' or patname like 'X%';
select patname from patient where trim(patname) like '%z' or trim(patname) like '%X';
select patname from patient where patname like '_yz';
select * from patient where patid between 1 and 10; // including 1 and 10
select * from patient where exists(select * from appnt);
select avg(field/*), min(field/*), ... ;
select * from patient, appnt; //(patient * appnt)
select * from patient, appnt where patient.patid=appt.patid;
select patname, docname from patient, doctor where patient.patid = appt.patid and appt.patid = doc.patid;
select (list of fields, ... ) form table_1 inner join table_2 on table_1.common_field=table_2.common_field
Displays all the records of left table
select * table_1 left join table_2 on common_field_condition
select * table_1 right join table_2 on common_field_condition
select * table_1 right join table_2 on common_field_condition
select a.field_1, b.field_2 from table_1 a, table_2 b
select distinct d1.docname, d2.docid form doctor d1, doctor d2 where
(d1.docname=d2.docname) and (d1.gender <> d2.gender)
select (union_compatible fields, ... ) from table_1
interset
select (union_compatible fields, ...) from table_2
select (union_compatible fields, ... ) from table_1
union
select (union_compatible fields, ...) from table_2
select (union_compatible fields, ... ) from table_1
minus
select (union_compatible fields, ...) from table_2
select group_field, count(*) from table group by group_field
select group_field, count(*) from table
group by group_field
having our_condition