Introduction to Structured Query Language (SQL) – Part – 3
In What Manner to Delete A Table or Relation
If an individual have previously implemented the original CREATE TABLE statement then the database will have the table or relation known as XYZBank . Customer . Details, so let’s remove that by means of the DROP statement:
DROP TABLE XYZBank . Customer . Details;
Now, we’ll reconstruct the XYZBank . Customer . Details table and we’ll make use of it throughout the rest of this article:
CREATE TABLE [ XYZBank ] . [ Customer ] . [ Details ] ( CustomerID VARCHAR (10) NOT NULL , Name VARCHAR (30) NOT NULL, Gender VARCHAR (7) NOT NULL, Address VARCHAR (MAX) NOT NULL , EmailID VARCHAR (25) NOT NULL , Phone INT NOT NULL , SocialSecurityID VARCHAR (15) NOT NULL )
Data Manipulation Language (DDL) in Structured Query Language (SQL)
The Structured Query Language (SQL) is also comprised of commands to Update, Insert, as well as Delete data. These query plus update statement collectively form the Data Manipulation Language (DML) part of Structured Query Language (SQL):
• INSERT – This command add new information into a database table or relation.
• UPDATE – This command alters the existing information in the database table or relation.
• DELETE – This commands removes the existing information from a database table or relation.
• SELECT – This command fetch the required information form the database table or relation.
In What Manner to Insert Information
As of now we are having our database named XYZBank and the table or relation XYZBank . Customer . Details formed; hence it is time to insert some data in the table or relation. In the huge majority of desktop database applications, the data entry is done by means of a graphical user interface (GUI) forms. This form provides a demonstration of the data that are essential for the application, rather than providing a general plotting onto the tables. In this type of circumstances the database end user is protected both from the fundamental arrangement of the database as well as from the Structured Query Language (SQL) which may possibly be castoff to enter information into it. But, in this article we’ll be using the Structured Query Language (SQL) directly to insert, update as well as to delete the data from tables or relations.
The individual can insert row or tuple by means of the INSERT Data Modification Language (DML) command. The code of the INSERT command is as follows:
INSERT [ INTO ] { My_Table_Name } [ ( My_Column_Name ) ] VALUES { DEFAULT | My_Values | My_Select_Command }
here,
· My_Table_Name – It stipulates the name of the table or relation into which the information is to be added. The INTO keyword is a non – compulsory keyword.
· My_Column_Name – It stipulates a non – compulsory constraint. An individual can make use of it at the time of fractional information insertion in a table or relation otherwise at the time of insertion in the columns or attributes in a dissimilar arrangement compare to the definition of the columns or attributes in the table or relation.
· DEFAULT – It stipulates the section which an individual can practice to add the by default data stated for the column or attributes. If a by default data is not stated for a column or attribute plus the column or attribute data is stated as NULL, then the NULL value is added in the column or attribute. If the column or attribute do not have some by default limitation devoted to it as well as do not permit the NULL value as the column or attribute data, then SQL Server generates an inaccuracy message as well as the insertion process is disallowed.
· My_Values – It stipulates the data values for the table or relation columns or attributes which have to be added as a row or tuple in the table or relation. When the column or attribute is to be given a by default data, an individual can use the DEFAULT keyword as an alternative of a column or attribute data value. The column or attribute data value can be an expression too.
· My_Select_Command – It stipulates a multiple inside (Nested) SELECT command which an individual can practice to add rows or tuples in the table or relation.
Therefore, to insert the data in the XYZBank . Customer . Details table or relation, an individual can make use of the following syntax:
INSERT INTO [ XYZBank ] . [ Customer ] . [ Details ] ( CustomerID , Name , Gender , Address , EmailID , Phone , SocialSecurityID ) VALUES ( ‘ C#25001 ’ , ‘ My Name ’ , ‘ Male ’ , ‘ My Address Line 1 , Address Line 2 ’ , ‘ MyEmailID . com ’ , ‘ 0123456789 ’ , ‘ SSID#3535359 ’ )
Apparently inserting data in a database by means of a sequence of Structured Query Language (SQL) statements is both tiresome as well as likely to have errors, this is an additional cause why database applications have front ends forms for data entry purpose. Even without exactly designed front end, several database systems – counting MSSQL – permits direct data entry into tables or relation by means of a spreadsheet like interface.
The INSERT statement can also be castoff to create replica of data from one table or relation to another. For an instance, the Structured Query Language (SQL) query to perform this is:
INSERT INTO [ XYZBank ] . [ Customer ] . [ Details ] ( CustomerID , Name , Gender , Address , EmailID , Phone , SocialSecurityID ) SELECT CustomerID , Name , Gender , Address , EmailID , Phone , SocialSecurityID FROM [ XYZBank ] . [ Customer ] . [ OldDetails ]
In the upcoming part we will be discussing in what manner to update information, in what way to delete information, how to make use of transaction control language (TCL) in structured query language (SQL) and how to operate with transaction control language (TCL).