how to create a table
|
CREATE TABLE table_name (
|
column1 datatype,
|
column2 datatype,
|
column3 datatype,
|
....
|
);
|
CREATE TABLE Persons (
|
PersonID int,
|
LastName varchar(255),
|
FirstName varchar(255),
|
Address varchar(255),
|
City varchar(255)
|
);
|
create table using another table
|
CREATE TABLE new_table_name AS
|
SELECT column1, column2,...
|
FROM existing_table_name
|
WHERE ....;
|
CREATE TABLE TestTable AS
|
SELECT customername, contactname
|
FROM customers;
|
| how to create a table with constraings datatypes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE table_name ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column1 datatype constraint, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column2 datatype constraint, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column3 datatype constraint, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| not null | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE Persons ( | without data it will not accept | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ID int NOT NULL, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LastName varchar(255) NOT NULL, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FirstName varchar(255) NOT NULL, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Age int | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
);
|
default
|
|
using this we can made that value is default, if user is not
entered, that default value is show
|
|
CREATE TABLE Persons (
|
|
ID int NOT NULL,
|
|
LastName varchar(255) NOT NULL,
|
|
FirstName varchar(255),
|
|
Age int,
|
|
City varchar(255) DEFAULT 'Sandnes'
|
|
);
|
|
CREATE TABLE Orders (
|
|
ID int NOT NULL,
|
|
OrderNumber int NOT NULL,
|
date
|
OrderDate date DEFAULT GETDATE()
|
|
);
|
|
autoincriment
| |
CREATE TABLE Persons (
| |
Personid int NOT NULL AUTO_INCREMENT,
| |
LastName varchar(255) NOT NULL,
| |
FirstName varchar(255),
| |
Age int,
| |
PRIMARY KEY (Personid)
| |
);
| |
No comments:
Post a Comment