sql commands1
sql commands1
1. To create database
Syntax :
create database databasename;
Eg:
create database school;
3. To select database
Syntax:
use databasename;
Eg:
use school;
4. To create table
Syntax:
CREATE TABLE tablename(
attributename1 datatype constraint,
attributename2 datatype constraint,
:
attributenameN datatype constraint);
Eg:
create table student(RNO char(5) primary key,NAME varchar(25),MARK int(3) not null);
create table Admin(Admno char(7),class char(10),RNO char(5));
34. Data Deletion DELETE statement is used to delete/remove one or more records
from a table.
Syntax:
DELETE FROM table_name WHERE condition;
Eg:
Delete from student where mark is null;
35. Single Row Functions These are also known as Scalar functions. Single row
functions are applied on a single value and return a single value. Figure 9.3 lists
different single row functions under three categories — Numeric (Math), String,
Date and Time
Math functions:
36. Aggregate Functions Aggregate functions are also called Multiple Row
functions. These functions work on a set of records as a whole and return a single
value for each column of the records on which the function is applied
37. Group By cLauSe In SQL At times we need to fetch a group of rows on the basis
of common values in a column. This can be done using a group by clause. It groups
the rows together that contains the same values in a specified column. We can use
the aggregate functions (COUNT, MAX, MIN, AVG and SUM) to work on the
grouped values. HAVING Clause in SQL is used to specify conditions on the rows
with Group By clause
38.operations on relations We can perform certain operations on relations like
Union, Intersection and Set Difference to merge the tuples of two tables. These three
operations are binary operations as they work upon two tables. Note here that these
operations can only be applied if both the relations have the same number of
attributes and corresponding attributes in both tables have the same domain. 9.10.1
UNION (∪) This operation is used to combine the selected rows of two tables at a
time. If some rows are same in both the tables, then result of the Union operation
will
show those rows only once. Figure 9.4 shows union of two sets. Music Dance
Figure 9.4: Union of two sets Let us consider two relations DANCE and MUSIC
shown in Tables 9.18 and 9.19 respectively.
c) Explicit use of NATURAL JOIN clause The output of queries (a) and (b) shown
in Table 9.26 has a repetitive column Ucode having exactly the same values. This
redundant column provides no additional information. There is an extension of
JOIN operation called NATURAL JOIN which works similar to JOIN clause in
SQL but removes the redundant attribute. This operator can be used to join the
contents of two tables if there is one common attribute in both the tables.