" /> Password <br /><input type="password" name="passwd" id="passwd" class="inputbox" size="18" alt="password" />
Home SQL Default
PDF

DEFAULT

SQL DEFAULT constraints in CREATE TABLE

The following SQL creates DEFAULT in the column "City, when creating a table" Persons ":

My SQL / SQL Server / Oracle / MS Access:

1
2
3
4
5
6
7
CREATE TABLE Persons (
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Sandnes'
)

1
2
3
4
5
6
CREATE TABLE Orders (
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
OrderDate date DEFAULT GETDATE()
)

SQL DEFAULT Restrictions on ALTER TABLE

The following SQL creates DEFAULT in the column "City, when the table" Persons "has already been established:

MySQL:

1
2
ALTER TABLE Persons
ALTER City SET DEFAULT 'SANDNES'

SQL Server / Oracle / MS Access:

1
2
ALTER TABLE Persons
ALTER COLUMN City SET DEFAULT 'SANDNES'

Removing DEFAULT

To remove a constraint DEFAULT, use the following SQL:

MySQL:

1
2
ALTER TABLE Persons
ALTER City DROP DEFAULT

SQL Server / Oracle / MS Access:

1
2
ALTER TABLE Persons
ALTER COLUMN City DROP DEFAULT

Comments

 
+6 #1 Студент 2010-06-07 21:18 Thank you very much creator of the site is very helpful in preparing for the exam in the database:) Quote
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Advertisement