0% found this document useful (0 votes)
41 views6 pages

The CREATE TABLE Statement: Mis - I - SQL Work Sheet - 1

The document discusses various SQL statements used to manage tables and data in a database. It begins by explaining how to create a table using the CREATE TABLE statement. It then covers how to insert, select, update, and delete data from tables. Additional statements covered include ALTER TABLE to modify columns, SELECT DISTINCT to return only unique values, and WHERE to filter records. Examples are provided for each statement type using a sample STUDENT table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

The CREATE TABLE Statement: Mis - I - SQL Work Sheet - 1

The document discusses various SQL statements used to manage tables and data in a database. It begins by explaining how to create a table using the CREATE TABLE statement. It then covers how to insert, select, update, and delete data from tables. Additional statements covered include ALTER TABLE to modify columns, SELECT DISTINCT to return only unique values, and WHERE to filter records. Examples are provided for each statement type using a sample STUDENT table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MIS – I | SQL WORK SHEET – 1

MBA –MS 2019-21 Batch

SQL is followed by a unique set of rules and guidelines called Syntax. All the SQL statements
start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE.
The most important point to be noted here is that SQL is case insensitive, which means SELECT
and select have same meaning in SQL statements.

The CREATE TABLE Statement


The CREATE TABLE statement is used to create a new table in a database.

Syntax
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. char() varchar(),
number, date, etc.).

Exercise : 1

CREATE TABLE STUDENT (


NAME CHAR(100),
ID NUMBER,
AGE NUMBER,
ADDRESS VARCHAR(500),
DOB DATE);

............................................................................................................................................................................................................................

The DROP TABLE Statement


The DROP TABLE statement is used to drop an existing table in a database.

Syntax
DROP TABLE table_name;

Note : You can try it out later if you want to delete the table from the database.

............................................................................................................................................................................................................................
The INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.

Syntax
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

If you are adding values for all the columns of the table , make sure the order of the values is in
the same order as the columns in the table.

Exercise : 2

INSERT INTO STUDENT (NAME, ID,AGE, ADDRESS, DOB)


VALUES (‘ SABASTIN’,001,30,’NO-30, WOOD WINDS , BANGALORE’ , TO_DATE
(‘17/11/1986’,’DD/MM/YYYY’));

Note : Enter 5 values

............................................................................................................................................................................................................................

The SELECT Statement


The SELECT statement is used to select data from a database.

The data returned is stored in a result table, called the result-set.

Syntax
SELECT column1, column2, ...
FROM table_name;

Here, column1, column2, ... are the field names of the table you want to select data from. If you
want to select all the fields available in the table, use the following syntax:

Syntax
SELECT * FROM table_name;

Exercise : 3

Case 1: ( Display all the content)

SELECT *
FROM STUDENT;

Case 2: ( only selected attribute)

SELECT NAME, AGE


FROM STUDENT;
............................................................................................................................................................................................................................

The SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to
list the different (distinct) values.

Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;

Exercise : 4

SELECT DISTINCT NAME


FROM STUDENT;

............................................................................................................................................................................................................................

The UPDATE Statement


The UPDATE statement is used to modify the existing records in a table.

Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE
statement. The WHERE clause specifies which record(s) that should be updated. If you omit the
WHERE clause, all records in the table will be updated

Exercise : 5

UPDATE STUDENT
SET AGE =31
WHERE ID=001;

............................................................................................................................................................................................................................

The DELETE Statement


The DELETE statement is used to delete existing records in a table.

Syntax
DELETE FROM table_name WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE
statement. The WHERE clause specifies which record(s) should be deleted. If you omit the
WHERE clause, all records in the table will be deleted!

Exercise : 6

DELETE FROM STUDENT


WHERE NAME = ‘SABASTIN’;
It is possible to delete all rows in a table without deleting the table. This means that the table
structure, attributes, and indexes will be intact:

Syntax
DELETE FROM table_name;

Note : You can try it out later if you want to delete the data inside the table.

............................................................................................................................................................................................................................

The WHERE Clause


The WHERE clause is used to filter records.

The WHERE clause is used to extract only those records that fulfill a specified condition.

Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Note: The WHERE clause is not only used in SELECT statement, it is also used in UPDATE,
DELETE statement, etc.!

Operators in The WHERE Clause

The following operators can be used in the WHERE clause:

Operator Description
= Equal
<> Not equal. 
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between a certain range
IN To specify multiple
possible values for a
column
Exercise : 7
SELECT *
FROM STUDENT
WHERE NAME=’SABASTIN’;

SELECT *
FROM STUDENT
WHERE NAME <>’SABASTIN’;

SELECT *
FROM STUDENT
WHERE AGE > 20;

SELECT *
FROM STUDENT
WHERE AGE < 30;

SELECT *
FROM STUDENT
WHERE AGE >= 20;

SELECT *
FROM STUDENT
WHERE AGE <= 30;

SELECT *
FROM STUDENT
WHERE ID BETWEEN 001 AND 005;

SELECT *
FROM STUDENT
WHERE NAME IN (‘Sabastin’, ‘Shirl’);

............................................................................................................................................................................................................................

ALTER TABLE Statement


The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

The ALTER TABLE statement is also used to add and drop various constraints on an existing
table.

ALTER TABLE - ADD Column


To add a column in a table, use the following syntax:

Syntax
ALTER TABLE table_name
ADD column_name datatype;

Exercise : 8

ALTER TABLE STUDENT


ADD FATHER_NAME CHAR(200);

ALTER TABLE - DROP COLUMN


To delete a column in a table, use the following syntax (notice that some database systems don't
allow deleting a column):

Syntax
ALTER TABLE table_name
DROP COLUMN column_name;

Exercise : 8

ALTER TABLE STUDENT


DROP COLUMN AGE;

Note :
To comment use –
............................................................................................................................................................................................................................

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy