HTML

Table:
A table is a collection of related data organized in a structured format with in a database.It contains rows and columns.
Syntax: 
            Create table table_name(
                         column1 datatype, 
                         column2 datatype,
                          ......);

Ex 1: Creating table Using Command. 
           

Ex 2: Creating table using management studio
 Step 1: Right click on the required database there you find an option table


Step 2: Click on the table and enter the fields i.e column name and related datatype


Step 3: After entering all the fields close the current window.when eve closing the current window then a box will open for confirming the changes.Press Yes
.

Step 4: After pressing Yes a box will open for generating Table name.

Enter the table name and press Yes.

Step 5: Inserting values to the created table.

Truncate:
  •  It is like delete command.
  •  If we truncate the table then only data will be deleted.
  •  It deletes all the data at a time where delete command deletes the data row by row.
  •  We can not use Where condition with truncate.
  •  We can not delete specific record with truncate.



Alter Command:
The alter command is used to add,delete and modify the columns in an existing table.

Ex 1:Adding column to an existing table.
Syntax: Alter table table-name add column_name datatype;

Inserting values to the table after adding of new column

Output:


Ex 2: Changing the size of the datatype
Syntax: Alter table table_name alter column column_name datatype(size);

Inserting the values

Output:


Ex 3: Changing the datatype of the column
Syntax: alter table table_name alter column column_name new datatype;

Output:

Ex 4: Changing the column name
Syntax: sp_rename '<table_name.column_name>',<new column_name>','<column>';

Output:


Ex 5: Droping the existing column
Syntax: alter table table_name drop column column_name;

Output: