SQL SERVER -- DDL Commands -- Part-3
DDL Commands:-DDL Stands for Data Definition language and these commands are used to CREATE, ALTER and DELETE database Objects.
CREATE – This command is used to create database objects
Like Database and Table.
-- How to Create New DataBase
CREATE DATABASE SQLSERVER
GO
-- How to go inside to the Database
USE SQLSERVER
GO
-- CREATE
-- How to Create New Table
CREATE TABLE EMP
(
EMPID INT
,EMPNAME VARCHAR(50)
,SAL MONEY
,DOJ DATE
,LOC VARCHAR(50)
,GENDER CHAR(6)
,MagrID INT
,DEPTNO INT
)
Like adding new column to the table
-- ALTER
-- How to Add New Column to the Table
ALTER TABLE EMP
ADD COUNTRY CHAR(100)
-- How to Drop the Column the Table
ALTER TABLE EMP
DROP COLUMN COUNTRY
TRUNCATE – This command is used to delete all records from a
table and resets table identity to initial value.
DROP – This command
is used to delete objects of the database
-- How to Drop the Table from the Database
DROP TABLE EMP
-- How to Drop the Column the Table
ALTER TABLE EMP
DROP COLUMN COUNTRY