SQL Server Syntax to Create, Select, Update, Delete Database, Tables, Columns, Stored Procedures

  Total Views : 521
  Comments : 0
 
  Keywords : SQL server syntaxes to create, insert, update, delete drop databases, tables and columns, SQL server predefined syntax formats to alter, insert, update, delete, drop tables, databases, etc

In SQL we can do lot of functionalities like create, delete, update, drop, truncate, insert many more operations on databases, tables and stored procedures for that we need to follow some of predefined syntaxes formats in SQL. In SQL we have few main keywords which we will used to start SQL statements those are

 

CREATE DATABASE - We will use this keyword to create new database

 

ALTER DATABASE – we can modify database details by using this keyword

 

DROP DATABASE - We will use this keyword to drop created database

 

CREATE TABLE – It will create new table

 

ALTER TABLE – It will allow us to modify table details

 

DELETE TABLE – It will delete data from table

 

DROP TABLE – It will drop complete table from database

 

CREATE INDEX – This keyword is used to create index on table

 

DROP INDEX – This keyword is used to drop index from table

 

INSERT INTO – This keyword is used to insert data in table(s)

 

SELECT – This keyword is used to get data from table(s)

 

UPDATE – This keyword is used to update data in table(s)

 

CREATE PROCEDURE – This keyword is used to create stored procedure

 

ALTER PROCEDURE – This keyword is used to modify existing stored procedure from database

 

DROP PROCEDURE – This keyword is used to deleted stored procedure from database

 

Note: SQL is not a case sensitive that means CREATE DATABASE or create database both statements are same

 

Now we will learn syntaxes for all these keywords in SQL.

SQL CREATE DATABASE Syntax

Following is the syntax of creating 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

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User