SQL Syntax

The SQL Syntax start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;).

Important SQL Commands

  • Create Database - Creates a new database
  • Alter Database - Modifies a database
  • Create Table - Creates a new table
  • Drop Table - Deletes a table
  • Alter Table - Modifies a table
  • Select - Extracts data from a database
  • Update - Updates data in a database
  • Delete - Deletes data from a database
  • Insert Into - Inserts new data into a database
  • Create Index - Creates an index
  • Drop Index - Deletes an index

Create DATABASE

The CREATE DATABASE statement is used to create a new SQL database. Database names must be unique within an instance of SQL Server and comply with the rules for identifiers.

Create DATABASE Syntax

CREATE DATABASE database_name;

Alter DATABASE

The Alter DATABASE statement is used to modify, maintain, or recover an existing database. OR It is used to change characteristics of a database.

Alter DATABASE Syntax

ALTER DATABASE database_name
MODIFY NAME [new_database_name];

Create TABLE

The CREATE TABLE statement is used to create a new Table in database.

Create TABLE Syntax

ALTER DATABASE CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.............);

Drop TABLE

The DROP TABLE statement is used to drop an existing table in a database.

Drop TABLE Syntax

DROP TABLE table_name;

Alter TABLE - ADD/DROP Column

ADD/DROP Column alter TABLE Syntax

ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name;

SQL SELECT Statement

The SQL SELECT Query use for 'fetch OR pull out' data value from database table.

Select Query Syntax

SELECT * from table_name;
SELECT * from table_name WHERE [condition];
SELECT [column_name] From table_name;
SELECT [column_name]
From table_name
WHERE [condition]
;

Note: Estic (*) use to access all data from data_table

SQL UPDATE Statement

The SQL UPDATE Query is used to changes the data of one or more existing records in a database table. We can update single columns as well as multiple columns using UPDATE Query as per our requirement.

Update Query Syntax

The basic syntax of the SQL Update command is as mentioned below:

UPDATE table_name
SET column_name1 = value1 column_name2 = value2.....
WHERE [condition];

Note: Condition to select the rows for which the values of columns needs to be updated.

SQL DELETE Statement

The SQL DELETE Query is used to delete rows that are no longer required from the database tables.

Delete Query Syntax

DELETE From table_name WHERE [condition];

SQL INSERT INTO Statement

SQL INSERT INTO Query is used to insert a new row in a table. There are two method of using INSERT INTO statement for inserting rows:

Insert Into Query Syntax

1) Only values - INSERT INTO

INSERT INTO table_name VALUES (value1, value2, value3,...);

2) Column names and values - INSERT INTO

INSERT INTO table_name
COLUMN (column1, column2, column3,..)
VALUES (value1, value2, value3,...);

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)