SQL Lesson1 tutorial
SQL Lesson1 tutorial
(SQL)
Lab Session
Lesson 1
DROP
UPDATE
DELETE
Example:
Create database myFirstDB;
The Drop statement:
Used to remove the databases.
Syntax:
Drop <object type> <object name>
Object type- can be database or table
Object name- can be database name or table name
Dropping Database
The most basic syntax for the DROP DATABASE statement looks like :
DROP DATABASE <database name>
Example:
Drop database myFirstDB;
Creating Tables
The ‘CREATE TABLE’ Statement
used to create a table in a database.
Syntax:
Use Database_Name
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
);
The data type specifies what type of data the column can
hold.
Example:
use myFirstDB
create table Student
(
stud_id varchar(10),
stud_Fname varchar(50),
stud_Lname varchar(50),
stud_age integer,
stud_sex varchar(50)
);
Adding Attributes
Syntax:
ALTER TABLE Table_Name
ADD column_name data_type;
The ALTER TABLE command allows the user to
change the structure of a table.
Example:
ALTER Table student
Add Stud_grade varchar(1);
Add Birthplace attributes on yours existing database
table ???
Deleting Attributes
Syntax:
ALTER TABLE Table_Name
DROP COLUMN column_name;
Example:
ALTER Table student
DROP COLUMN CGPA;
Example: