SQL Basic Statements

In SQL, to perform operations like create, delete, update, drop, truncate, insert, etc., operations on databases, tables, and stored procedures, we need to follow some of the predefined syntax formats.

 

Following are some basic SQL statements to perform operations like insert, update, delete, select on databases, tables, etc., based on our requirements.

 

StatementDescription
CREATE DATABASE This statement is useful to create a new database in sql.
ALTER DATABASE By using this statement, we can alter or modify existing database details.
DROP DATABASE This statement is useful to drop or delete an existing database in sql.
CREATE TABLE This statement is useful to create a new table in sql.
ALTER TABLE This statement is useful to modify existing tables in sql.
DELETE TABLE This statement is useful to delete records from tables in sql.
DROP TABLE This statement is useful to drop the complete table from sql database.
CREATE INDEX This statement is useful to create an index on the table.
DROP INDEX This statement is useful to drop an existing index on the table.
INSERT INTO This statement is useful to insert data into tables.
SELECT This statement is useful to get data from tables.
UPDATE This statement is useful to update the records in a table.
CREATE PROCEDURE This statement is useful to create a new stored procedure in sql database.
ALTER PROCEDURE This statement is useful to modify an existing stored procedure in sql database.
DROP PROCEDURE This statement is useful to delete an existing stored procedure in sql database.
SQL is not case sensitive, which means CREATE DATABASE or create database both statements are same.

The following are the syntaxes of the above sql statements to perform required operations in sql server.

SQL CREATE DATABASE Syntax

Following is the syntax of creating a new database in sql server.

 

CREATE DATABASE databasename

SQL ALTER DATABASE Syntax

ALTER DATABASE olddbName MODIFY NAME = newdbName

SQL DROP DATABASE Syntax

DROP DATABASE dbname

SQL CREATE TABLE Syntax

CREATE TABLE tablename
(
columnname1 datatype(size),
columnname2 datatype(size),
columnname3 datatype(size),
......
)

SQL ALTER TABLE Syntax

ALTER TABLE tablename ADD columnname datatype

Or

ALTER TABLE tablename DROP COLUMN columnname

Or

ALTER TABLE tablename ALTER COLUMN columnname datatype

SQL DELETE TABLE Syntax

DELETE FROM tablename

or

DELETE FROM tablename where columnname=somevalue

SQL DROP TABLE Syntax

DROP TABLE tablename

SQL CREATE INDEX Syntax

CREATE INDEX indexname ON tablename(columnname)

SQL DROP INDEX Syntax

DROP INDEX tablename.columnname

SQL INSERT INTO Syntax

INSERT INTO tablename(column1,column2,column3,..,columnN)
VALUES(value1,value2,value3,..valueN)

SQL SELECT Syntax

SELECT column1,column2,column3,...,columnN from tablename

Or

SELECT * FROM tablename

SQL UPDATE Syntax

UPDATE tablename SET columnname1=value1, columnname2=value2

SQL CREATE PROCEDURE Syntax

CREATE PROCEDURE procedurename
@parameter datatype
AS
BEGIN
select * from tablename where columnname1=@parameter
END

SQL ALTER PROCEDURE Syntax

ALTER PROCEDURE procedurename
@parameter datatype,
@parameter2 datatype
AS
BEGIN
select * from tablename where columnname=@parameter and columnname2=@parameter2
END

SQL DROP PROCEDURE Syntax

DROP PROCEDURE procedurename