Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
49 views

Oracle 11g

The document provides SQL statements for: 1) Creating tables, adding, modifying and dropping columns, inserting data, and displaying constraints. 2) Performing queries with GROUP BY, HAVING, UNION, subqueries, aggregation functions, joins, LIKE, TOP, ORDER BY, IN, and BETWEEN clauses. 3) Altering tables by adding constraints, updating data values, setting columns to unused, and adding foreign keys.

Uploaded by

Matthew Cox
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Oracle 11g

The document provides SQL statements for: 1) Creating tables, adding, modifying and dropping columns, inserting data, and displaying constraints. 2) Performing queries with GROUP BY, HAVING, UNION, subqueries, aggregation functions, joins, LIKE, TOP, ORDER BY, IN, and BETWEEN clauses. 3) Altering tables by adding constraints, updating data values, setting columns to unused, and adding foreign keys.

Uploaded by

Matthew Cox
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 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;

You might also like