IT4A IDB Labs
IT4A IDB Labs
Labs’ Contents
BSIT 4th Semester - FICT, BUITEMS
Note: Typos are expected, please inform the instructor if any found
Lab 1
Inserting Data into Tables: - once a table is created the most natural thing to do is load this
table with data to be manipulated later.
o Syntax: INSERT INTO <table name> (<col1>,<col2>) VALUES(<exp>,<exp>);
o Exmple: INSERT INTO student (stuID, firstName) VALUES(1, ‘Hamza’);
Viewing data in the tables: - once data has been inserted into a table, the next most logical
operation would be to view what has been inserted
o To view all fields and their data
Syntax: SELECT * FROM tablename;
Example: SELECT * FROM students
o To view all fields and their data
Syntax: SELECT <column name> ,<column name> FROM tablename;
Example: SELECT stuID FROM tableName;
o Filed Aliases/ Column Aliases
o Syntax: SELECT <column name> AS <alias> FROM tablename;
o Example: SELECT stuID AS ‘IDs of Students’ FROM students;
Lab 3
The Save (Not Permitted) dialog box warns you that saving changes is not permitted because
the changes you have made require the listed tables to be dropped and re-created.
The following actions might require a table to be re-created: Adding a new column to the
middle of the table
Dropping a column
Changing column nullability
Changing the order of the columns
Changing the data type of a column <<<<
To change this option, on the Tools menu, click Options, expand Designers, and then click
Table and Database Designers. Select or clear the Prevent saving changes that require
the table to be re-created check box
SELECT…WHERE Clause
o SYNTAX: SELECT <fieldName1, FieldName2> FROM <TableName> WHERE
<fieldToWhichConditionRequired> <someOperator> <someValue>
o SELECT * FROM STUDENTS WHERE GPA > 3
OR
o SYNTAX: SELECT <fieldName1, FieldName2> FROM <TableName> WHERE
<fieldToWhichConditionRequired> <someOperator> <someValue> OR
<fieldToWhichConditionRequired> <someOperator> <someValue>
NOT Operator
o SYNTAX: SELECT <fieldName1, FieldName2> FROM <TableName> WHERE
<fieldToWhichConditionRequired> <!someOperator> <someValue> OR/AND
<fieldToWhichConditionRequired> <!someOperator> <someValue>
o EXAMPLE: SELECT firstName, lastName from students WHERE firstName!
=’Hamza’ OR firstName!=’Shayan’
Between Clause
o SYNTAX: SELECT <fieldName1, FieldName2> FROM <TableName> WHERE
<fieldToWhichConditionRequired> <BETWEEN> <someValue> AND
<someValue2>
Lab 4
o EXAMPLE: SELECT * from students ORDER BY Age ASC
CONSTRAINT fk_name
FOREIGN KEY (child_col1)
REFERENCES parent_table (parent_col1)
)
Adding Composite Foreign Key while creating table
CREATE TABLE child_table
(
column1 datatype [ NULL | NOT NULL ],
column2 datatype [ NULL | NOT NULL ],
...
CONSTRAINT fk_name
FOREIGN KEY (child_col1, child_col2, ... child_col_n)
REFERENCES parent_table (parent_col1, parent_col2, ... parent_col_n)
)
To delete all the records from a table without deleting the table do
TRUNCATE TABLE <table Name>
To remove an entire table from the database use the DROP command.
DROP TABLE tablename
Lab 5