How to Create Query in SQL, Create Table, Delete Table and User Insert Info Statements

How to Create Query in SQL, Create Table, and Delete Table and User Insert Info Statements

In this tutorial, you will learn how to How to Create Query in SQL, Create Table, Delete Table and User Insert Info Statements. Making an essential table includes naming the table and characterizing its sections and every segment’s information sort. 

Making an essential table includes naming the table and characterizing its sections and every segment’s information sort.

CREATE TABLE

The SQL CREATE TABLE articulation is utilized to make another table.

Syntax:

Basic syntax of CREATE TABLE statement is as follows:

CREATE TABLE table_name(

                Coluimn1 datatype.

                Column2 datatype,

                ….

                ColumnN datatype,

                PRIMARY KEY (one or more columns)

);

Make TABLE is the catchphrase telling the database framework what you need to do. For this situation, you need to make another table. The interesting name or identifier for the table takes after the CREATE TABLE articulation.

At that point in sections comes the rundown characterizing every segment in the table and what kind of information sort it is. The language structure gets to be clearer with an illustration underneath.

A duplicate of a current table can be made utilizing a mix of the CREATE TABLE explanation and the SELECT proclamation.

INSERT INTO

The SQL INSERT INTO Statement is utilized to add new lines of information to a table in the database.

Syntax:

There are two basic syntaxes of INSERT INTO statement as follows:

INSERT INTO TABLE_NAME (Column1, Column2, …, ColumnN)

VALUES (Value1, Value2, …, ValueN);

Here, Column1, Column2, …, ColumnN are the names of the sections in the table into which you need to embed information.

You will not have to determine the column(s) name in the SQL inquiry in the event that you are including values for every one of the segments of the table. Be that as it may, ensure the request of the qualities is in the same request as the sections in the table. The SQL INSERT INTO language structure would be as per the following: 

INSERT INTO TABLE_NAME VALUES (Value1, Value2, …, ValueN);

Example:

Following statements would create three records in BOOKS table: 

                INSERT INTO BOOKS (ID, BOOK_NAME, AUTHOR, ISBN, PRICE )

                VALUES (1, “SOFTWARE ENGINEERING”, “ABC AUTHOR”, “XXX-XXXX-XX”, 34.00);

 

                INSERT INTO BOOKS (ID, BOOK_NAME, AUTHOR, ISBN, PRICE )

                VALUES (2, “PROGRAMMING WITH C++”, “XYZ AUTHOR”, “XXX-XXXX-XX”, 24.00);

 

                INSERT INTO BOOKS (ID, BOOK_NAME, AUTHOR, ISBN, PRICE )

                VALUES (3, “COMPUTER NETWORKS”, “LMN AUTHOR”, “XXX-XXXX-XX”, 28.00);

 

SELECT

SQL SELECT explanation is utilized to bring the information from a database table which returns information as result table. These outcome tables are called result-sets.

Syntax:

The basic syntax of SELECT statement is as follows:

SELECT Column1, Column2, …, ColumnN FROM TABLE_NAME

Here, column1, column2…are the fields of a table whose qualities you need to get. In the event that you need to get every one of the fields accessible in the field, then you can utilize the accompanying sentence structure:

SELECT * FROM TABLE_NAME

UPDATE

The SQL UPDATE Query is utilized to alter the current records in a table.

You can utilize WHERE statement with UPDATE inquiry to redesign chose pushes generally every one of the columns would be influenced.

Syntax:

The basic syntax of UPDATE query with WHERE clause is as follows: 

UPDATE table_name

SET Column1 = Value1, Column2 = Value2, …, ColumnN = ValueN

WHERE (Condition)

Example:

Consider the BOOKS table having the following records:

ID Book_Name Author ISBN Price
1 SOFTWARE ENGINEERING ABC Author XXX-XXXX-XX 34.00
2 PROGRAMMING IN C++ XYZ Author XXX-XXXX-XX 24.00
3 COMPUTER NETWORKS LMN Author XXX-XXXX-XX 28.00

Taking after is a case, which would upgrade the Price for a book whose ID is 2: 

UPDATE BOOKS

SET PRICE = 20.00

WHERE ID = 1; 

Now, BOOKS table would have the following records:

ID Book_Name Author ISBN Price
1 SOFTWARE ENGINEERING ABC Author XXX-XXXX-XX 34.00
2 PROGRAMMING IN C++ XYZ Author XXX-XXXX-XX 20.00
3 COMPUTER NETWORKS LMN Author XXX-XXXX-XX 28.00

DELETE

The DELETE statement is used to delete records within a table.

You can utilize WHERE statement with DELETE statement to delete a particular record within the table.

Syntax:

DELETE FROM table_name

WHERE Column_Name = Value;

 

For Example:

Consider the BOOKS table having the following records:

ID Book_Name Author ISBN Price
1 SOFTWARE ENGINEERING ABC Author XXX-XXXX-XX 34.00
2 PROGRAMMING IN C++ XYZ Author XXX-XXXX-XX 20.00
3 COMPUTER NETWORKS LMN Author XXX-XXXX-XX 28.00

Taking after is a case, which would delete the book record whose ID is 3:

 

DELETE FROM BOOKS

WHERE ID = 3;

 

Now, BOOKS table would have the following records:

ID Book_Name Author ISBN Price
1 SOFTWARE ENGINEERING ABC Author XXX-XXXX-XX 34.00
2 PROGRAMMING IN C++ XYZ Author XXX-XXXX-XX 20.00

More Related Articles For You

    DBMS Tutorial

    SQL and DBMS Interview Questions with Answers

    DBMS and SQL Practice Tests , Questions and Quizzes

Search

Shortcodes Ultimate

 
Follow Us
 
BGP