1602048262data Defination Language
1602048262data Defination Language
By Habibi 1
Database Creation
before creating .MDF and .LDF files by explicitly
we should need to follow the following properties:
Name: it will represent the logical names of the file
(.MDF and .LDF) and these names should be
different.
File Name: it will represent the path location of the
files that means anywhere we can store the files.
Size: it will represent the initial size of the file.
Maxsize: it will represent the maximum size of the
file.
File Growth: it will represent the growth of the file
(1 MB), it means that will plus 1 with minimum size
for every single entry in the database.
By Habibi 2
Example:
Name=’XYZ’
Size=8MB
Maxsize=15MB
File Growth=1MB
By Habibi 6
C-Remove .MDF and .LDF Files from an
existing Database:
Syntax: alter database <database name>
remove file <logical name>
Example1: alter database MyDemo remove file
XYZ or ABC------>we cannot remove primary
files, but it can be removed when database is
removed from server.
Exmaple2: alter database MyDemo remove file
MNO or PQR------> we can remove secondary
files from a database.
By Habibi 7
D-Modify the Database Name:
Syntax: alter database <old database name>
modify name <new database name>
Example: alter database MyDemo modify
name=MyOne
Note: we can change database name but we cannot
change the file names
E-Dropping a Database: - when we drop a database
then all the associated files are dropped from database
permanently.
Syntax: drop database <database name>
Example: drop database MyOne
By Habibi 8
Table Creation
In Database every object will save with an extension of
dbo. <Object name> such as dbo. Employee,
Syntax: create table <Table Name> (<column-
name1><data type>[size], <column_name2><data
type>[size])
Create table students (stdID int, SName char(10) SFee
decimal (6,2), Age tinyint)
Syntax to view the structure of a table is: SP_HELP
Students
By Habibi 9
Rules for creating a new table in Database
1. The table name should be Unique within the same
Database.
2. The column name should be unique within the table
definition.
3. The table name should not start with numbers and
special characters except under score _.
4. Don’t provide the space in the table name if you want
to provide a space in the table name then we use _
symbol.
5. Don’t use the Reserved keywords (insert, select,
update) as a table name.
6. A table name should contain minimum 1 character
and maximum 128 characters only.
7. A table should contain minimum 1 column and
maximum 1024 columns only.
By Habibi 10
Alter the table
To change the structure of a table, Alter command
perform the following 4 operations on an existing table :
By Habibi 11
Cont…
By Habibi 12
Cont.…..
2- Alter Table: this command will use to add the new
columns to the table.
By Habibi 15
C-Truncate
it is used to delete all rows from the table permanently
and cannot restore the dropped rows.
By using truncate command we cannot delete a specific
row from a table because the truncate command does not
support ‘Where’ key word.
It will drop all rows form a table but cannot drop the
structure of the table.
Syntax: truncate table <table name>
Example: truncate table students
By Habibi 16
D-Drop
it will drop the entire structure of the table from the
database permanently and cannot restore the structure
of the table.
By Habibi 17
Any Questions & Suggestions
By Habibi 18