Skip to main content

Database Knowledge for a Tester Part II


1 SQL Concepts

1.1 Basic Data Types


1.2 Basic SQL Commands

1.1.1 Create Table

SYNTAX:
CREATE TABLE [Table Name] ([ColumnName1] [Datatype] ([size]), [ColumnName..n] [Datatype] ([size]));
Rule for creating table:
· Name can have maximum upto 30 chars.
· Name should begin with an Alphabet (A-Z, a-z) and optionally followed by numbers (0-9)
· Special character “_” underscore is allowed and also recommended.
· SQL reserved words like create, select etc are not allowed.
E.g.
CREATE TABLE employee (employee_no varchar2 (10), employee_name varchar2 (25));

1.1.2 Insert Data into Tables

SYNTAX:
INSERT INTO [TABLE NAME] ([COLUMNNAME1], [COLUMNNAME...N]) VALUES ([EXPRESSION1], [EXPRESSION2]);
For e.g.
INSERT INTO employee (employee_no, employee_name) VALUES (‘E001’, ‘Sachin Kumar’);
Note: Character & Date expressions placed with in the INSERT INTO statement must be enclosed in single quotes.
In INSERT INTO if the number of values is same as the number of column then there is no need to provide the column name in the INSERT INTO command provided the expression are provided in the same sequence and data type as defined during CREATE TABLE.
However if there is less values being inserted into the table, then it is mandatory to include both the Column Name and corresponding value in the INSERT INTO SQL command.

1.1.3 Viewing Table Data

View All Rows and All ColumnsSELECT * FROM [TABLE NAME];
Selected Column and All RowsSELECT [COLUMNNAME1], [COLUMNNAME…N] FROM [TABLE NAME];
Selected Rows and All ColumnsSELECT * FROM [TABLE NAME] WHERE [CONDITION];
Here [CONDITION] is always quantified as [ColumnName=Value]
Note: All Standard operators such as logical, arithmetic, predicates etc can be used when specifying where clause.Selected Column and Selected Rows
SELECT [COLUMNNAME1], [COLUMNNAME…N] FROM [TABLE NAME] WHERE [CONDITION];
Here [CONDITION] is always quantified as [ColumnName=Value]
Note: All Standard operators such as logical, arithmetic, predicates etc can be used when specifying where clause.Distinct Data or Eliminate Duplicate RecordsSELECT DISTINCT [COLUMNNAME1], [COLUMNNAME…N] FROM [TABLE NAME];
Display unique column values.SELECT DISTINCT * FROM [TABLE NAME];
Display unique rows from all the records.

1.1.4 Sorting Table Data

Syntax:
SELECT * FROM [TABLE NAME] ORDER BY [COLUMNNAME1], [COLUMNNAME…N] [[SORT ORDER]];
Note: The ORDER BY Clause can only be used in Select Statements.The Default sort order is ASC (ascending). To sort the record in descending order use DESC keyword as Sort Order.

1.1.5 Updating Table

Updating All RowsUPDATE [TABLENAME] SET [COLUMNAME1] = [EXPRESSION1], [COLUMNAME…N] = [EXPRESSION…N];
Conditional Update of RecordsUPDATE [TABLENAME] SET [COLUMNAME1] = [EXPRESSION1], [COLUMNAME…N] = [EXPRESSION…N] WHERE [CONDITION];

1.1.6 Alter Table

ALTER TABLE allows:
· Add/Delete columns
· Create or Destroy indexes
· Change the data type of existing columns
ALTER TABLE cannot be used for:
· Changing the name of the table & column
· Decrease the size of a column if table data exists.

SYNTAX:
Adding New ColumnALTER TABLE [TABLE NAME] ADD ([NEWCOLUMNNAME1] [DATATYPE]([SIZE]), [NEWCOLUMNNAME…N] [DATATYPE]([SIZE]));
Dropping A Column From a TableALTER TABLE [TABLE NAME] DROP COLUMN [COLUMNNAME];
Modifying Existing ColumnsALTER TABLE [TABLE NAME] MODIFY ([COLUMNNAME] [NEWDATATYPE] ([NEW SIZE]));
Note: To use Alter Table command, the ALTER, INSERT & CREATE privileges for the table are required.

1.1.7 Delete Table

Removal of All RowsDELETE FROM [TABLE NAME];
Removal of Specific RowsDELETE FROM [TABLE NAME] WHERE [CONDITION];

1.1.8 Truncate Table

Truncate Table like Delete Table deletes all rows from the table but there are some practical differences under some circumstances:
· Truncate is much faster than Delete as Truncate first drop the table and then re-create it.
· Truncate operations are not Transaction safe in case of any error while execution.
· The number of deleted rows are not returned.
Syntax
TRUNCATE TABLE [TABLENAME];

1.1.9 Drop Table

Drop table dropped all records from the table and permanently destroy table from the database which cannot be recovered.
Syntax:
DROP TABLE [TABLENAME];

1.2 Examining Objects Created by a User

1.2.1 Finding out the table/s Created by a user

SELECT * FROM TAB;
The tables created under the currently selected tablespace are displayed.

1.2.2 Displaying the table structure

DESCRIBE [TABLENAME];
The command displays the column names, the data types, and the special attributes connected to the table.

2. References

SQL, PL/SQL Third Edition by Ivan Bayross.

3. Download

Click here to download a PDF copy of this Article.

Comments

Popular posts from this blog

Mantis - Defect Management Tool - User Guide

Introduction This white paper contains information related to an open source defect management tool called Mantis which is freely available for managing all your defects. Where to Download One can download the latest version of Mantis from http://sourceforge.net/project/showfiles.php?group_id=14963 Download the “mantis-stable” and then “mantis-x.y.z.zip”.1.1 PRE-REQUISITE Operating System Windows 2003 Server, MacOS, OS/2, Linux, Solaris Database MySQL database 3.23.2 and higher Software PHP 4.0.6 and higher Application Server Apache 1.3, Apache 2.0.54, IIS 6.0 with Web Services Extension Browser IE6 and above, Mozilla Firefox STEPS FOR INSTALLATION – FOR WINDOWS MySQL Installation Install MySQL by downloading it from http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r6-win32.msi/from/http:/www.mirrorservice.org/sites/ftp.mysql.com/ . Please follow the below mentioned steps while installing MySQL: (Please remember the password for “root” account...

Why to do Software Testing?

Regardless of the limitations, testing is an integral part in software development. It is broadly deployed in every phase in the software development cycle. Typically, more than 50% percent of the development time is spent in testing. Testing is usually performed for the following purposes: To improve quality. As computers and software are used in critical applications, the outcome of a bug can be severe. Bugs can cause huge losses. Bugs in critical systems have caused airplane crashes, allowed space shuttle missions to go awry, halted trading on the stock market, and worse. Bugs can kill. Bugs can cause disasters. The so-called year 2000 (Y2K) bug has given birth to a cottage industry of consultants and programming tools dedicated to making sure the modern world doesn't come to a screeching halt on the first day of the next century. [Bugs] In a computerized embedded world, the quality and reliability of software is a matter of life and death. Quality means the conformance to the ...

HP QTP Tutorial - Chapter 10

1 Debug In my previous chapter, I discussed about the features available in Resources Menu such as Object Repository, OR Manager, and Associate Repositories etc. This chapter covers the features available under Debug Menu option. This chapter explains the following features available under Debug Menu : The features under Debug menu are very useful and also frequently used. Although in most of the cases you use Short Keys. We will cover all these features in detail in this chapter. 1.1 Pause  There could be case when are you running your script and want to pause (remember Pause and Stop are different things), then you can navigate to Debug ->Pause. The script will be paused at the current execution step. You can then do your analysis and then continue with your run by clicking on Automation-> Run. Alternatively you can also Press F5 or Run button from the tool bar.  1.2 Step Into  There are situation in a script which makes call to other Action or Funct...