Sql Queries and its solution for BSC(H) Computer Science 4th Sem Enjoy!!!!!!!!!Description complète
Description complète
Full description
what is difference between ATTRIBUTE column & GLOBAL_ATTRIBUTE column in a table? If i want to define more DFF than ATTRIBUTE column in a table then what we should do? and many mor question answered.
Sql Queries and its solution for BSC(H) Computer Science 4th Sem Enjoy!!!!!!!!!Descripción completa
Description complète
SQL QUERIES
queriesFull description
Full description
SQL AssignmentFull description
sql best query
Oracle Apps SQL Queries
sql queries Hotel DatabaseFull description
Collection of SQL Queries with answers... interview questions..
questions related to transformationsFull description
Full description
Full description
for sql interview for beginers
Full description
STUDY OF SQL QUERIES
DDL COMMANDS
DATA DEFINITION LANGUAGE The DDL commands are:• • • • •
Create table Alter table Drop table Create view Drop view
The create command when applied with above specification creates the field of different data type. 2. ALTER COMMAND:-
Syntax: a) alter table add (column_name datatype (size)); Description:
The alter command when used with add allows us to add an additional column to an already existing table. Syntax: b) alter table < table_name> modify(column_name datatype(size));
Description:
The alter command when used with modify redefines the column with the given values but cannot change the column names. Syntax: c)
alter table drop(column_name);
Description:
The alter command when used with drop deletes the specified column in the table. 3.
DROP COMMAND:-
Syntax: Drop table ; Description:
A table can be dropped (deleted) by using a drop table command. 4.
CREATE VIEW COMMAND:-
Syntax: Createview as select from where ; Description:
A view is named, derived, virtual table. A view takes the output of a query and treats it as a table; a view can be thought of as a “stored query” or a “virtual table”. The tables upon which a view is based are called base tables. 5. DROP VIEW COMMAND:-
Syntax: Drop view ; Description:
A view can be dropped (deleted) by using a drop view command. 6. TRUNCATE COMMAND:-
Syntax: Truncate table ; Description:
The details in the table are deleted but the table structure remains.
7. RENAME COMMAND:-
Syntax: Rename to ; Description:
The old table name is replaced with the new table name.
PROGRAM TO LEARN DDL COMMANDS CREATE TABLE:
SQL> create table lists(name varchar(14),code number(4),price number(3),quantity number(3)); Table created. SQL> desc lists; Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR(14) CODE NUMBER(4) PRICE NUMBER(3) QUANTITY NUMBER(3) ALTER TABLE:
SQL> alter table lists add(sellinprice number(4)); Table altered. SQL> desc lists; Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR(14) CODE NUMBER(4) PRICE NUMBER(3) QUANTITY NUMBER(3) SELLINPRICE NUMBER(4) SQL> alter table lists drop(sellinprice); Table altered. SQL> desc lists;
Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR (14) CODE NUMBER(4) PRICE NUMBER(4) QUANTITY NUMBER(3) CREATE VIEW:
SQL> create view listsview as select * from lists; View created. SQL> desc listsview;
Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR(14) CODE NUMBER(4) PRICE NUMBER(4) QUANTITY NUMBER(3) SQL> select * from listsview;
Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR(14) CODE NUMBER(4) PRICE NUMBER(4) QUANTITY NUMBER(3) RENAME:
SQL> rename lists to list; Table renamed. SQL> desc lists; ERROR: ORA-04043: object lists does not exist. SQL> desc list;
Name Null? Type ---------------------------------- -------- ---------------------------NAME VARCHAR(14) CODE NUMBER(4) PRICE NUMBER(4) QUANTITY NUMBER(3) DROP TABLE:
SQL> drop table list; Table dropped. SQL> desc list; ERROR: ORA-04043: object lists does not exist.
DML COMMANDS
DATA MANIPULATION LANGUAGE The DML commands are:
• • •
Insert Delete Update
1.
INSERT :-
Syntax : Insert into values (val1,val2,…); Description:
The ‘insert into’ command insert the values in the specified table. In the insert into SQL sentence the column and values have a one to one relationship (i.e.) the first value described into the first column, the second value described being inserted into the second column and so on. 2. DELETE: Syntax: Delete from where ; Description:
The delete in SQL is used to remove rows from table. To remove, 1. All the rows from a table. 2. A select set of rows from a table. 3. UPDATE: Syntax: Update set fieldname= where ; Description:
The update command is used to change or modify data values in a table. To update, 1. All the rows from a table. 2. A select set of rows from a table.
PROGRAM TO LEARN DML COMMANDS INSERTION:
SQL> insert into lists values('&name',&code,&price,&quantity) Enter value for name: powder Enter value for code: 101 Enter value for price: 50 Enter value for quantity: 5 old 1: insert into lists values('&name',&code,&price,&quantity) new 1: insert into lists values('powder',101,50,5) 1 row created. SQL> insert into lists values ('dhal',102,45,10); 1 row created. SQL> insert into lists values ('masala`,103, 20,12) 1 row created. SQL> insert into lists values ('powder `104, 30,8) 1 row created. SQL> insert into lists values ('icecream`,105, 70,5) 1 row created. SQL> insert into lists values ('pen`,106, 10,20) 1 row created. SQL> insert into lists values ('icecream`,107,40,5) 1 row created. SQL> select * from lists;
NAME ------------- powder dhal masala powder icecream pen icecream
DATA QUERY LANGUAGE The DML commands are: Select Order by
Group by Having Null
1. SELECT STATEMENT: Syntax: a) select from [where clause]; Description:
Select command is used to retrieve data from one or more tables or columns. The attributes list is a list of attributes name whose values are displayed by query. A missing where clauses indicate no condition on tuples selection. The condition is a Boolean expression that identifies the tuples to be retrieved by the query. Syntax: b) select distinct from ; Description:
Display the distinct values from a table by eliminating the duplicate values. It performs grouping of the specified fields when queried with distinct statement. 2. ORDER BY CLAUSE: Syntax: Select from order by ; Description:
Order by sorts the output of any specified column or expression. The order by clause must always have task in any select statement. The default order is ascending order. We should specify the keywords ‘desc’ if we wand it in descending order. 3. GROUP BY CLAUSE: Syntax: Select from group by ; Description:
The group by clause specifies the grouping of function to appear in the select clause. So that the value resulting from group of tuples appear along with the values of grouping attributes are SUM, AVERAGE, MAX, MIN and COUNT. 4. HAVING CLAUSE: Syntax:
Select from where group by condition> having ; Description:
The ‘having’ clause is used to specify certain conditions on rows, retrieved by using group by clause. This clause should be preceded by a ‘group by’ clause. 5. NULL COMMAND: Syntax: Select NVL(substitution column,substitutied value) from where ; Description:
The NVL function helps in substituting the value in the null fields. But this function only displays the change and does not update the columns.
TRANSACTION CONTROL LANGUAGE The TCL commands are: Commit Rollback Save point
1.COMMIT: Syntax: set auto commit on; set auto commit off; commit; Description:
Commit commands tells the DBMS to make permanent changes made to temporary copies of the data updating the permanent database tables to match the updated temporary copies. 2.ROLL BACK: Syntax: rollback; Description:
Roll back tells the DBMS to undo any changes made to the DBMS after the most recent commit. 3.SAVE POINT: Syntax: savepoint ; Description:
Save point are like markers to divide a very lengthy transaction to smaller ones. They are used to identify a point in transaction to which we can later rollback. Thus savepoint is used in conjunction with rollback to rollback portions of the current transaction.
DATA CONTROL LANGUAGE The DCL commands are: Grant Revoke
1. GRANT: Syntax: Grant on to user; Description:
Grand gives specifies SQL statement access or individual data objects to a user or a group of users. 2. REVOKE: Syntax: Revoke on from user; Description:
Revoke removes specific SQL statement access previously granted on individual database objects from a user or group of users.