Data Definition Language-DDL
Data Definition Language-DDL
a. CREATE Statement
b. ALTER Statement
c. DROP Statement
d. TRUNCATE Statement
a. CREATE Statement: This Statement is used for creating the database and its
objects .
b. ALTER Statement: This Statement is used for modifying the database and its
objects
c. DROP Statement: This Statement is used for deleting the database and its objects
After writing the above Query in SQL Server Management Studio then select it and press
F5. Then server creates database with name SAMLE, that we can check it in Database list
box in SSMS
Primary data files: Every database has one primary data file. This file contains the
startup information for the database and is used to store data. The name of primary
database file has the extension MDF(master data file).
Secondary data files: These files hold all of the data that does not fit into the primary
data file. A database can have zero or more Secondary data files. The name of secondary
database file has the extension NDF(next data file).
Transaction Log files: These files hold the log information used to recover the database.
There must be at least one log file for each database. The name of a Log file has the
extension LDF(log data file).
1. Primary File: It was defined by the server with 1.18 mb size and with
extension “. mdf” (master data file) for holding start up information of the
database.
Ex: SAMPLE. Mdf
2. Log File: It was defined by the server with 504 kb size and with extension
“. ldf” (log data file) for holding transaction information of the database.
Ex: SAMPLE. ldf
The above two queries creates two tables with names CUSTOMER, EMP
The above query extends the SAMPLE database to 5mb by adding new file
SAMPLE.NDF.
Syntax to ALTER the Table: In Three ways we can modify the tables
Syntax:
ALTER TABLE TABLENAME ADD NEWCOLUMN DATATYPE [,……..N]
Syntax:
ALTER TABLE TABLENAME ALTER COLUMN COLUMNNAME NEWDATATYPE
The above statement changes the EMPNO data type from INT to BIGINT.
The above statement deletes two existing columns ENAME, SAL columns from EMP
Table.
Note: It is not possible to drop a particular database which is currently in use it means it
is not possible to drop SAMPLE database and till we enter in to another database
Note: Users can DROP multiple Databases at a time by placing comma (,) between the
database names but it is not recommended approach.
The above statement deletes all data available in EMP table in PAGE-BY-PAGE manner
(all at once) with out disturbing its structure (Columns)