Saturday, February 25, 2023

SQL Server - CREATE, INSERT, ALTER, DROP, UPDATE Tables

 


CREATE TABLE 

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

Syntax :

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
);

Example :

CREATE TABLE Employee (
    EmpId int,
    Name varchar(255),
    Address varchar(255),
    City varchar(255)
);
 

 

INSERT TABLE 

The INSERT TABLE statement is used to insert data into table in a database.

Syntax :

INSERT INTO table_name (column1,  column2, column3)

Values (value1, Value2, Value3)

Example :

INSERT INTO Employee (EmpId,  Name, City)

Values (101, ‘Rajendra’, ‘Mumbai’)


ALTER TABLE 

The ALTER TABLE statement is used to alter table structure.

Syntax :

ALTER TABLE table_name

ADD New Field DataType

Example :

ALTER TABLE Employee

ADD DOB DATETIME NULL


DROP TABLE 

The DROP TABLE statement is used DELETE table permanently from database

Syntax :

DROP TABLE table_name

Example :

DROP TABLE Employee


UPDATE TABLE

UPDATE TABLE statement used modify/update existing table data

Syntax ;

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;

Example:

UPDATE Employee
SET Name = ‘Ishanth’, City = ‘Delhi’
WHERE EmpId= 101;

No comments:

Post a Comment

SQL Server - Introduction to SQL

  Introduction to SQL   SQL is a standard language for accessing and manipulating databases. SQL stands for Structured Query Language. SQL...