• HTML INTRODUCTION

    The HTML 5 language has a "custom" HTML syntax that is compatible with HTML 4 and XHTML1 documents published on the Web, but is not compatible with the more esoteric SGML features of HTML 4.

  • JAVASCRIPT Introduction

    JavaScript (JS) is a dynamic computer programming language.

  • Structured Query Language (SQL)

    SQL is a standard language for accessing databases.

  • AJAX INTRODUCTION

    AJAX = Asynchronous JavaScript and XML.

  • ASP

    ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.

  • Save a lot of work with CSS!

    In our CSS tutorial you will learn how to use CSS to control the style and layout of multiple Web pages all at once.

  • C# (programming language)

    c# (pronounced as see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, procedural, generic, object-oriented (class-based), and component-oriented programming disciplines.

  • Java - Overview

    Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).

  • jQuery is a JavaScript Library

    jQuery greatly simplifies JavaScript programming.

  • PHP LANGUAGE PROGRAMMING

    PHP is a server scripting language, and is a powerful tool for making dynamic and interactive Web pages quickly.

  • Introduction to XML

    XML was designed to transport and store data.HTML was designed to display data.

Thursday, September 5, 2013

Posted by amikitinfo
No comments | 9:31 PM
The SQL ALTER TABLE command is used to add, delete, or modify columns in an existing table.
You would also use ALTER TABLE command to add and drop various constraints on a an existing table.

Syntax:

The basic syntax of ALTER TABLE to add a new column in an existing table is as follows:

ALTER TABLE table_name ADD column_name datatype;
 
The basic syntax of ALTER TABLE to DROP COLUMN in an existing table is as follows:

ALTER TABLE table_name DROP COLUMN column_name;
 
The basic syntax of ALTER TABLE to change the DATA TYPE of a column in a table is as follows:

ALTER TABLE table_name MODIFY COLUMN column_name datatype;
 
The basic syntax of ALTER TABLE to add a NOT NULL constraint to a column in a table is as follows:

ALTER TABLE table_name MODIFY column_name datatype NOT NULL;
 
The basic syntax of ALTER TABLE to ADD UNIQUE CONSTRAINT to a table is as follows:

ALTER TABLE table_name 
ADD CONSTRAINT
MyUniqueConstraint UNIQUE(column1, column2...);
 
The basic syntax of ALTER TABLE to ADD CHECK CONSTRAINT to a table is as follows:

ALTER TABLE table_name 
ADD CONSTRAINT
MyUniqueConstraint CHECK (CONDITION);
 
The basic syntax of ALTER TABLE to ADD PRIMARY KEY constraint to a table is as follows:

ALTER TABLE table_name 
ADD CONSTRAINT
MyPrimaryKey PRIMARY KEY (column1, column2...);
 
The basic syntax of ALTER TABLE to DROP CONSTRAINT from a table is as follows:

ALTER TABLE table_name 
DROP CONSTRAINT
MyUniqueConstraint;
 
If you're using MySQL, the code is as follows:

ALTER TABLE table_name 
DROP INDEX
MyUniqueConstraint;
 
The basic syntax of ALTER TABLE to DROP PRIMARY KEY constraint from a table is as follows:

ALTER TABLE table_name 
DROP CONSTRAINT
MyPrimaryKey;
 
If you're using MySQL, the code is as follows:

ALTER TABLE table_name 
DROP PRIMARY KEY
;

Example:

Consider CUSTOMERS table is having following records:

+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
 
Following is the example to ADD a new column in an existing table:

ALTER TABLE CUSTOMERS ADD SEX char(1);
 
Now CUSTOMERS table is changed and following would be output from SELECT statement:

+----+---------+-----+-----------+----------+------+
| ID | NAME | AGE | ADDRESS | SALARY | SEX |
+----+---------+-----+-----------+----------+------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 | NULL |
| 2 | Ramesh | 25 | Delhi | 1500.00 | NULL |
| 3 | kaushik | 23 | Kota | 2000.00 | NULL |
| 4 | kaushik | 25 | Mumbai | 6500.00 | NULL |
| 5 | Hardik | 27 | Bhopal | 8500.00 | NULL |
| 6 | Komal | 22 | MP | 4500.00 | NULL |
| 7 | Muffy | 24 | Indore | 10000.00 | NULL |
+----+---------+-----+-----------+----------+------+
 
Following is the example to DROP sex column from existing table:

ALTER TABLE CUSTOMERS DROP SEX;
 
Now CUSTOMERS table is changed and following would be output from SELECT statement:

+----+---------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Ramesh | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | kaushik | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+---------+-----+-----------+----------+

0 comments:

Post a Comment

Hosting Gratis