0% found this document useful (0 votes)
9 views3 pages

SQL Dbms

Uploaded by

suneha2003datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

SQL Dbms

Uploaded by

suneha2003datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

sab small letters e likhkeo hbe

CREATE TABLE x
(
column_name TYPE(size) CONSTRAINTS, #NOT NULL/NULL/UNIQUE/AUTO_INCREMENT
---if unique it must not have mor than one nulls
PRIMARY KEY (col_name), #(columnname datatype (size) primary key,….)
FOREIGN KEY (col_name) REFERENCES tablename(col_name), #(columnname datatype
(size) references another table name);
colname TYPE(size) Check (expression),
constraint cname foreign key (col_name)
);

CREATE TABLE TABLENAME


[(columnname, columnname, .......)] # tuple of colsnames inside a list
AS SELECT columnname, columnname .... FROM tablename;

#...........chelekhela with table er column.........#


ALTER TABLE x ADD column_name TYPE();
ADD PRIMARY KEY (columnname);
ADD CONSTRAINT constraintname FOREIGN KEY(columnname) REFERENCES
tablename(col_name);
ALTER TABLE x MODIFY (column_name NEWTYPE); #ADD (column_name NEWTYPE);
ALTER TABLE x RENAME COLUMN column_name TO new_name
ALTER TABLE x DROP COLUMN col_name / DROP (many col_name separated by,);
DROP PRIMARY KEY
DROP CONSTRAINT constraintname;

# .......table nie chelekhela........#


DROP TABLE x;
TRUNCATE TABLE x ; // table thakbe but empty columns datas drop koro

# .......column er values nie chelekhela........#


INSERT INTO x(many col_name separated by,) VALUES(corresponding values);
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;

SELECT col_names FROM x WHERE //jerm column sequence likbo orm show hbe
UPDATE x SET col_name=valuenew WHERE rowspecification
DELETE FROM x WHERE //kon row delete krvo

TYPE
_______________
NUMBER
VARCHAR
DATE - format YYYY-MM-DD
DATETIME - format: YYYY-MM-DD HH:MI:SS
TIMESTAMP - format: YYYY-MM-DD HH:MI:SS
YEAR - format YYYY or YY
• Int- An integer.
• Small integer- A small integer.
• Numeric (p, d)-A Fixed point number with user defined precision.
• Real, double precision- Floating point and double precision floating point
numbers with machine dependent precision.
• Float (n)- A floating point number, with precision of at least n digits.
WHERE
__________
id IN(1,2,3);
name='Suneha';
instead of WHERE or as extra write ORDER BY col_name ASC / DESC;
id=3 AND name='suneha';
id=3 OR name='suneha';
SELECT DISTINCT colname
id BETWEEN 12 AND 17;
name LIKE '%SU';
‘ ---- ‘ matches any string exactly three characters.
SELECT INTCAP() LTRIM() RTRIM(colname) UPPER() LOWER()
NVL(colname,value) LENGTH(colname),
SUBSTR(col,start,end:1 indexing)
COUNT() SUM() AVG() ROUND() MAX()// GROUP BY another column
//ex SELECT SUM(marks)
// SELECT SUM(marks) GROUP BY section here only to show less rows HAVING
SUM(marks) >30

JOINS
___________
SELECT col1 FROM x1
UNION INTERSECT MINUS
SELECT col2 FROM x2

SELECT cols of both tables


FROM x INNER JOIN , LEFT OUTER JOIN , RIGHT OUTER JOIN y
ON x.xid=y.id

-----difference btwn SELECT col AS and FROM col C


---- COMMIT, ROLLBACK---// TO SAVE OR UNDO CHANGE
--------last e kom row er jnno LIMIT BY

___________________________________________________________________________________
______________

SELECT col1 + col2 AS cname FROM tablename

functions
---------

ABS( col1 - col2)


ROUND(col,2)
CEIL()
FLOOR()
COMCAT(col1 , " " , col2)
SUBSTR(col,1,5)
INTCAP(col)
--at the end of query ORDER BY colname DESC LIMIT 5
--select......from ... GROUP BY colnames separated by comma as combination HAVING
SUM(COL) >50 ORDER BY ...

-----------------------------------------------------------------------------------
----------------------------------------------------------------
JOINS(interpolate table --->>>)
------

select colnameasitis from table1 tt CROSS JOIN table2 bt


INNER JOIN ON tt.col = bt.col

UNIONS( interpolate table V down)


-------

in case of UNION both tables must have same columns


QUERY(view 1) UNION QUERY(view 2)

UNION ALL (with repeatation)

-----------------------------------------------------------------------------------
------------------------------------------------------------------

subquery
-----------

independent
_____________

query ..where =(query) as a value


IN(query) as a list
query .. FROM (query) A as a table A

dependent
____________

---ei row ta dko ebr nebo kina depends on ---- next query

You might also like