Unit 3 Basics of QB Solution
Unit 3 Basics of QB Solution
Command: CREATE
Syntax:
CREATE TABLE table_name
(Column1 datatype (size),
Column2 datatype (size),
Column3 datatype (size));
Syntax:
➢ To create a new table from existing table – only few columns of existing tables are
required
Syntax:
E.g. Create table named student2 having 2 columns (Aadhar & name) similar to column
sid & name of existing table student
Syntax:
DROP TABLE tablename;
Syntax:
ALTER TABLE existing table_name
ADD COLUMN new column name datatype (size);
E.g. to add new column named aadhar of datatype number in existing table named
student
alter table student
add column aadhar numeric (10);
➢ To modify size of datatype of the column of existing table
Syntax:
ALTER TABLE existing table_name
ALTER COLUMN column name TYPE datatype (new size)
E.g. to modify size of datatype from 10 to 15 of column named aadhar in existing table
named student
alter table student
alter column aadhar type numeric (15);
E.g. to modify datatype of column named aadhar in existing table named student from
numeric to varchar (10) (to convert numeric to text)
Syntax:
ALTER TABLE existing table_name
ALTER COLUMN column name TYPE new datatype (size) # (to convert numeric to text)
Syntax:
ALTER TABLE existing table_name
DROP COLUMN column name;
E.g. to drop/delete column named aadhar in existing table
alter table student
drop column aadhar;
➢ TO rename Column in existing table
Syntax:
ALTER TABLE existing table_name
RENAME COLUMN column name TO new column name;
E.g. to rename column named name to sname in existing table
alter table student
rename column name to sname;
Syntax:
ALTER TABLE existing table_name
RENAME TO new table name;
E.g. to rename table name student to std in existing table
alter table student
rename to std;
Command: TRUNCATE
Syntax:
TRUNCATE TABLE tablename;
Syntax:
INSERT INTO table name (column1, column2, column3,….columnN)
VALUES (value1, value 2, value 3,…. valueN);
Syntax:
INSERT INTO table name
VALUES (value1, value 2, value 3,…. valueN);
Command: UPDATE
Syntax
update student
set sid=5 where sid=4;
E.g. Update age = 17 and dob = 2006-12-05
Syntax
update student
set age='17',dob='2006-12-05' where sid=1;
Command: Delete
Syntax
alter table T2
add column Deptname varchar (10);
Update T1
Set Designation = ‘Senior Manager’ where Empno = 1;
(1) After Creating table add one new column named Email_id of Varchar type with
size=12
Create table
Create table member
(ID char (6),
Name varchar (30),
Fee integer,
DOJ date);
Update member
Set doj = ‘2020-05-12’ where id = 2;
Update member
Set name = ‘yrt where id = 4;