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

Revolutionize software testing with AI! 🤖💻 Share your thoughts on ethical implications in the comments.

  As technology evolves, so too does the field of software testing. One exciting development in recent years is the use of AI (Artificial Intelligence) to automate repetitive tasks and improve testing accuracy. Through analyzing large amounts of data and identifying patterns, AI can help identify potential defects or vulnerabilities in software. AI-powered tools can also generate test cases and scenarios by simulating user behavior and input, allowing for more efficient and effective testing. In addition, machine learning algorithms can analyze and learn from past testing data, leading to better predictions and more streamlined testing. AI-powered tools can also help identify and prioritize critical bugs and defects, saving valuable time and effort in manual testing. But it's important to note that AI-powered testing is not a replacement for human testers. While AI can automate certain tasks and help identify potential issues, it's still necessary for human testers to provide a

Is AI taking over your job in software development and testing? 😱"

Are you a software developer or tester feeling threatened by the rise of AI in your industry? 😰 You're not alone. Many professionals in the field are concerned about the potential consequences of AI's integration into software development and testing. While some experts believe that AI can bring significant benefits to the industry, others worry that it could replace human expertise altogether. 🤔 AI algorithms can analyze massive amounts of data and automate many tasks, but they cannot replace the critical thinking and creativity of human beings. Additionally, there are ethical concerns associated with the use of AI in software development and testing. So, what can you do to ensure that you're not replaced by AI in your job? 💪 First, it's essential to recognize that AI is not a replacement for human expertise but rather a tool to augment it. Therefore, it's essential to learn how to work with AI-powered systems to increase your efficiency and productivity. Additi

HP Quality Center - Best Practices

1.Introduction Quality Center is a test management tool which provides very good features for managing both your manual and automated test cases. This paper highlights the best practices for managing your test cases. When you open Quality center, depending on your rights it display the below mentioned option in the sidebar: 1. Requirements 2. Test Plan 3. Test Lab 4. Defects 5. Dashboard 2.Requirements When you have assigned with the responsibility of developing your test cases in the quality center then you must be wondering where to start with. I am going to share my experience to overcome such a situation. You need to find the solution of some question before you start writing your test cases. 1. Is your requirement developed and available? 2. Is your requirement organized in a logical sequence? If answer to both of the above question is Yes, then you can start with Requirement option in the side bar. In case your requirement is under development, then you keep your