Вы находитесь на странице: 1из 3

ALTER TABLE TABLE NAME 

Create table ADD CONSTRAINT constraint_name 


CREATE TABLE [table name] CHECK (condition)
( [column name] [datatype], UPDATE
... ); UPDATE​ tablename ​SET
column​=​'VALUE'​;
CREATE TABLE tablename as (select
Add a foreign key constraint
col1, col2, .. from tablename)
ALTER TABLE TABLENAME
Add column
ADD CONSTRAINT
ALTER TABLE [table name]
ADD ( [column name] tablename_colname_FK FOREIGN
[datatype], ... ); KEY(colname)
Modify column REFERENCES
ALTER TABLE [table name] parent_tablename(colname);
MODIFY ( [column name] [new UNUSED
datatype] ); ALTER TABLE tablename SET UNUSED
Drop column column status;
ALTER TABLE [table name] SUBQUEREY
DROP COLUMN [column name]; select colname from tablename
where fcolname = (select colname
insert using the VALUES keyword from tablename where
INSERT​ ​INTO​ ​table_name​ ​VALUES colname='VALUE');
UPDATE MULTIPLE
(​'Value1'​, ​'Value2'​, ... );
UPDATE tablename SET
​INSERT​ ​INTO​ ​table_name​( Column1, colname='&colname',
Column2, ... ) ​VALUES​ ( ​'Value1'​, colname='&colname'
'Value2'​, ... ); WHERE colname=value;
CREATE TABLE tablename
Displaying constraints
(col name datatype,
SELECT
col name datatype,
table_name,
constraint_name, col name datatype,
constraint_type FirstName VARCHAR2(20),
FROM user_constraints; LastName VARCHAR2(20),
Phone# NUMBER(10),
Setting constraints on a table
CREATE TABLE table_name Email VARCHAR2(40),
( Address VARCHAR2(20),
column1 datatype null/not City VARCHAR2(20),
null, Province CHAR(2),
column2 datatype null/not PostalCode VARCHAR2(6),
null,
... CONSTRAINT tablename_colname_ty
CONSTRAINT constraint_name CONSTRAINTP (colname),
CHECK (column_name condition) CONSTRAINT tablename_colname_ty
[DISABLE] CONSTRAINTYPE (colname IN ('xx', 'xx','))

);
//group by having
SELECT column1, column2 //having
FROM table1, table2 SELECT column1, column2
WHERE [ conditions ] FROM table1, table2
GROUP BY column1, column2 WHERE [ conditions ]
HAVING [ conditions ] GROUP BY column1, column2
ORDER BY column1, column2 HAVING [ conditions ]
//union ORDER BY column1, column2
SELECT column1 [, column2 ]
FROM table1 [, table2 ] //update
[WHERE condition] UPDATE table_name
SET column1 = value1, column2 = value2....,
UNION columnN = valueN
WHERE [condition];
SELECT column1 [, column2 ]
FROM table1 [, table2 ] //subquerey
[WHERE condition] SELECT column_name [, column_name ]
FROM table1 [, table2 ]
//create table WHERE column_name OPERATOR
CREATE TABLE table_name( (SELECT column_name [, column_name ]
column1 datatype, FROM table1 [, table2 ]
column2 datatype, [WHERE])
column3 datatype,
..... AVG() COUNT() SUM() MIN() MAX()
columnN datatype,
PRIMARY KEY( one or more columns ) //JOINS
); SELECT Orders.OrderID,
Customers.CustomerName, Orders.OrderDate
//like FROM Orders
SELECT FROM table_name INNER JOIN Customers ON
WHERE column LIKE 'XXXX%' Orders.CustomerID=Customers.CustomerID;
//top
SELECT TOP number|percent column_name(s) //IN
FROM table_name SELECT column_name(s)
WHERE [condition] FROM table_name
//orderby WHERE column_name IN (value1, value2, ...);
SELECT column-list //between
FROM table_name SELECT column_name(s)
[WHERE condition] FROM table_name
[ORDER BY column1, column2, .. columnN] WHERE column_name BETWEEN value1 AND
[ASC | DESC]; value2;