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 predefined syntax formats in SQL.

 

Following are the some of basic sql statements to perform an 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 an existing database details.
DROP DATABASE This statement is useful to drop or delete an existing database in sql.
CREATE TABLE This statement is used to create a new table in sql.
ALTER TABLE This statement is used to modify an existing tables in sql.
DELETE TABLE This statement is used to delete a records from tables in sql.
DROP TABLE This statement is useful to drop complete table from sql database.
CREATE INDEX This statement is used to create a index on table.
DROP INDEX This statement is used to drop an existing index on table.
INSERT INTO This statement is used to insert a data into tables.
SELECT This statement is used to get a data from tables.
UPDATE This statement is used to update the records in table.
CREATE PROCEDURE This statement is used to create a new stored procedure in sql database.
ALTER PROCEDURE This statement is used to modify an existing stored procedure in sql database.
DROP PROCEDURE This statement is used to delete an existing stored procedure in sql database.
SQL is not a case sensitive that means CREATE DATABASE or create database both statements are same.

Following are the syntaxes of above sql statements to perform a 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