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

SQL Queries: 1.creating Two Tables With Data

1. Two tables were created - GAMES and PLAYER - to store information about games and players. 2. Sample data was inserted into both tables, including details for a carom board game and one player. 3. Queries were written to select, describe, alter, update, filter, aggregate, and order the data in various ways to demonstrate functionality of SQL.

Uploaded by

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

SQL Queries: 1.creating Two Tables With Data

1. Two tables were created - GAMES and PLAYER - to store information about games and players. 2. Sample data was inserted into both tables, including details for a carom board game and one player. 3. Queries were written to select, describe, alter, update, filter, aggregate, and order the data in various ways to demonstrate functionality of SQL.

Uploaded by

harsh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL QUERIES

1.Creating two tables With Data -:


Code -: CREATE TABLE GAMES
(
GCode NUMBER NOT NULL PRIMARY KEY,
GameName VARCHAR(30),
NOP NUMBER,
PrizeMoney FLOAT,
ScheduleDate DATE
);
CREATE TABLE PLAYER
(
PCode NUMBER NOT NULL PRIMARY KEY,
Name VARCHAR(30),
Gcode NUMBER
);
2.Insert Data into the tables GAMES & PLAYER -:
(Any one record is given from each table)

FOR GAMES-:
INSERT INTO GAMES VALUES(101,”Carom Board”,2,5000,”23-Jan-
2004”);
FOR PLAYER-:
INSERT INTO PLAYER VALUES(1,”Nabi Ahmad”,101);

3.Display all the data of table GAMES & PLAYER -:


Code -: SELECT * FROM GAMES;

GAMES -:

GCode GameName NOP PrizeMoney ScheduleDate


--------- ------------------ ------------------ ------------------ --------------------
101 Carom Board 2 5000 23-Jan-2004

102 Badminton 2 12000 12-Dec-2003

103 Table Tennis 4 8000 14-Feb-2004

105 Chess 2 9000 01-Jan-2004

108 Lawn Tennis 4 25000 19-Mar-2004


SELECT * FROM PLAYER;

PCode Name Gcode


PLAYERS -: --------- ------------------- -----------------
1 Nabi Ahmad 101

2 Ravi Sahai 108

3 Jatin 101

4 Nazneen 103

(USE OF SELECTION QUERY TO SHOW ONLY SELECTED PART OF DATA)

SELECT GCode,GameName FROM GAMES;

GCode GameName
--------- ------------------
101 Carom Board

102 Badminton

103 Table Tennis

105 Chess
3.DESC Table GAMES and PLAYER -:
108 Lawn Tennis
Code -: DESC GAMES;

DESC PLAYER;

4.Use of “ALTER” and ”UPDATE” Queries -:


Code -: ALTER TABLE PLAYER MODIFY Name VARCHAR(20);

UPDATE GAMES SET PrizeMoney=6000;

GCode GameName NOP PrizeMoney ScheduleDate


--------- ------------------ ------------------ ------------------ --------------------
101 Carom Board 2 6000 23-Jan-2004

102 Badminton 2 6000 12-Dec-2003

103 Table Tennis 4 6000 14-Feb-2004

105 Chess 2 6000 01-Jan-2004

108 Lawn Tennis 4 6000 19-Mar-2004

5.Use of “WHERE” Queries -:


CODE-: SELECT PCode,Name FROM PLAYER WHERE GCode=103;

PCode Name
---------------- ---------------------------
4 Nazneen

6.Use of “MIN”, “MAX”, “SUM” , “COUNT”, “DISTINCT” &


“ORDER BY”
CODE-: SELECT MAX(ScheduleDate) FROM GAMES;

ScheduleDate
--------------------
19-Mar-2004

SELECT MIN(ScheduleDate) FROM GAMES;

ScheduleDate
--------------------
12-Dec-2003
SELECT COUNT(*) FROM GAMES;

ScheduleDate
--------------------
19-Mar-2004

SELECT ScheduleDate FROM GAMES ORDER BY ScheduleDate;

ScheduleDate
--------------------
12-Dec-03

01-Jan-04

23-Jan-04

14-Feb-04

19-Mar-04

SELECT DISTINCT Gcode FROM PLAYER;

Gcode
-----------------
101

108

103

You might also like