0% found this document useful (0 votes)
16 views17 pages

Computer sem 5

Free study material

Uploaded by

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

Computer sem 5

Free study material

Uploaded by

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

COMPUTER SYSTEMS & APPLICATIONS

Q.1 (A): TRUE OR FALSE from EXCEL (2/3) 2 MARKS


(B): MULTIPLE CHOICE from MySQL (2/3) 2 MARKS
(C): TRUE OR FALSE from THEORY CHAPTERS (6/9) 6 MARKS
(D): MULTIPLE CHOICE from THEORY CHAPTERS (5/8) 5 MARKS
Q.2 (A): ANSWER THE FOLLOWING from THEORY CHAPTERS (1/2) 8 MARKS
(B): ANSWER THE FOLLOWING from THEORY CHAPTERS (1/2) 7 MARKS
Q.3 (A): WRITE MySQL CREATE TABLE QUERY (1/2) 8 MARKS
(B): BUILT IN FUNCTION IN MySQL / TABLE, COLUMN, ROW RELATED COMMAND 7 MARKS
Q.4 (A): ROW RELATED COMMAND OF MySQL (1/2) 8 MARKS
(B): ROW RELATED COMMAND OF MySQL (1/2) 7 MARKS
Q.5 (A): ATTEMPT from EXCEL (1/2) 8 MARKS
(B): ATTEMPT from EXCEL (1/2) 8 MARKS

THEORY NOTES
1. COMPONENTS OF DATA COMMUNICATION
A data communications system has five components:
 Message: The message is the data to be communicated. It can be text, numbers, pictures, audio and video.
 Sender: The sender is the device that sends the data message. It can be a computer, telephone handset, video
camera and so on.
 Receiver: The receiver is the device that receives the message. It can be a computer, telephone handset, video
camera and so on.
 Transmission medium: The transmission medium is the physical path by which a message travels from sender to
receiver. Some examples of transmission media include twisted-pair wire, coaxial cable, fiber-optic cable, radio
waves and so on.
 Protocol: A protocol is a set of rules for two devices to communicate. Communication is not possible without a
protocol.

2. NETWORK
Network is a group of computers and other devices, such as printers and scanners, connected by a communications link,
enabling all the devices to interact with each other and share applications, data and hardware components. Networks
can be small or large, permanently connected through wires or cables, or temporarily connected through phone lines or
wireless transmissions. The largest network is the Internet, which is a worldwide group of networks.

TYPES OF NETWORK
LAN (Local Area Network)
 It is a small network of connected computers, where in computers are connected to each other physically with
the help of wire or cable. (Though now-a-days there are wireless LANS, they come under WIRELESS NETWORK
(WLAN) and not LAN.)
 Each computer may work with peripheral devices such as printer, data storage devices.
 Connected computers must be within certain radius limit; generally, one kilometer. In other words, LAN is
confined to a small area.
 In LAN at least one computer is designed as file server. In some LAN file server is referred to as network drivers.
 The microcomputers managed by the file server are called as workstations or nodes.
 In LAN resources such as printers, data storage devices, software etc. can be shared.
 The file server manages the communication and sharing of peripheral devices.
 If required, LAN can contain more than one file server.
 Data transfer speed is measured in mega-bytes per second (MBPS) (10 MBPS or so).
 Two or more LANS can be connected to each other with the help of Bridges or Gateways.
 LAN is generally owned by an organisation. (Privately Owned)

MAN (Metropolitan Area Network)


 It is a bigger network of connected computers, where in computers are connected to each other physically with
the help of fiber optic cable.
 Each computer may work with peripheral devices such as printer, data storage devices.
 Connected computers must be within certain radius limit; generally, 40 to 60 kilo meters. In other words, MAN is
confined to a bigger area.
 Generally, MAN contains more than one file server.
 The microcomputers managed by the file server are called as workstations or nodes.
 In MAN resources such as printers, data storage devices, software etc. can be shared.
 The file server manages the communication and sharing of peripheral devices.
 Data transfer speed is measured in megabytes per second (MBPS) (20 MBPS or so).
 Two or more MANS can be connected to each other with the help of Bridges or Gateways.
 LAN can be connected to MAN.
 MAN is generally not owned by single organisation.

WAN (Wide Area Network)


 It is a large network of connected computers, where in computers are connected to each other with the help of
various communication facilities such as long-distance telephone services, satellite transmission, under sea-
cables etc.
 Each computer may work with peripheral devices such as printer, data storage devices.
 WAN covers wide geographical area. The connected computers can be anywhere in the world.
 Generally, WAN contains more than one file server.
 The microcomputers managed by the file server are called as workstations or nodes.
 In WAN resources such as data storage devices, software etc. can be shared.
 The file server manages the communication and sharing of peripheral devices.
 Data transfer speed is slow; it is measured in kilo bytes per second (kbps).
 Less freedom as compared to LAN, because public telecommunication is involved.
 MAN can be connected to WAN.

3. NETWORK TOPOLOGY (STRUCTURE)


The geometrical arrangement of computer resources, remote devices & communication facilities is known as network
topology or network structure. The network topology determines which element in a computer network can
communicate with each other.

Star Network
 This structure/ topology is commonly used.
 It consists of a centralised computer system from which the various communication channels originate.
 Each Terminal/ Computer can communicate only with the central computer system.
 If the terminals want to transfer data among themselves, it can be done only by sending the data to the central
computer system which in turn sends them to the destination.
 This structure is appropriate for organisation that requires a centralised data base on centralised data
processing facility.

Advantages
 Easy to add/remove nodes.
 A node failure does not bring down entire network.
 It is easier to diagnose network problems through a central computer.
Disadvantages
 Failure of central computer (server) will bring down entire network.
 As every node requires new cable; the cable cost is more.

Note: S Server and N = Nodes


Bus Network
 This structure is very popular for LAN. (Local Area Network)
 In this structure a single network cable runs in the building / Campus & all nodes are linked with this
communication line with two end points call as bus or backbone.
 The two ends of the cable are terminated with terminators.
Advantages
 Cable cost is reduced.
 Reliable in very small network and easy to understand and use.
 Easy to extend. Two cables can be easily joined with connector, making a longer cable for more computers to
join.
 Repeater can also be used to extend a bus configuration.
 Failure of any node does not affect the whole network.
Disadvantages
 Heavy network traffic can slow a bus network.
 Each connection between two cables weakens the electrical signal.
 If main cable fails, the whole network is damaged.
 Failure of main computer (server) will bring down entire network.

Note: S Server and N = Nodes

Ring/Loop Network
 It was commonly used network structure for LAN.
 It is an extension of bus network where last computer is connected with the first.
 In this topology the network cable passes from one node to another until all nodes are connected in a form of a
ring.
 There is direct point to point link between two neighbouring nodes.
 The links are unidirectional which ensures that transmission by node travels the whole ring and comes back to
the node, which made request for the transmission.
 Data is transmitted using Token Ring
Advantages
 Less cable cost.
 Ring network are easily extendable.
Disadvantages
 Failure of any node / Sever/ Cable will damage whole network.
 Data has to travel through every computer through transmission line.
 Relatively expensive and difficult to install.

Note: S-Server and N = Nodes


Mesh Network
 Refers to random arrangement of computers using telecommunication link.
 In this arrangement each computer & terminal is connected to each other by a dedicated point to point link &
thus eliminates routing function.
 This network provides high reliability as there are alternate paths available if the direct link between two nodes
is down or dysfunctional.
Advantages
 Direct connection is available between any two computers.
Disadvantages
 Cable cost is more.
 Difficult to install.

Note: S&N=Server and Nodes

4. NETWORK MEDIA (CHANNELS) / TYPES OF WIRES


Twisted-pair cable: Normally consists of four pairs of wires. Individual pairs have two wires that are separately insulated
in plastic, then twisted around each other and bound together in a layer of plastic. Except for plastic coating, nothing
shields this type of wire from outside interference, so it is also called as unshielded twisted- pair (UTP) wire. Some
twisted-pair wire is enclosed in a metal case and therefore called as shielded twisted-pair (STP) wire. Twisted-pair cable
is not immune to the electromagnetic interference. Data is transferred using electrical current. Now-a-days Twisted-pair
wires can support speed up to 100 Mbps. Twisted-pair cables are normally used for LAN. 2 pair cable uses RJ-11
connector. 4 pair cable uses RJ-45 connector. [RJ Registered Jack]. Signals must be "refreshed" every one to two miles
through the use of repeaters, which is expensive.
Coaxial cable: This cable has two conductors. One is a single wire in the centre of the cable, and the other is a wire mesh
shield that surrounds the first wire, with an insulator between. Coaxial cable is not immune to the electromagnetic
interference. Data is transferred using electrical current. It can support speed up to 10 Mbps. Coaxial cables were used
for LAN in the earlier days. It is easy to install and less expensive. Base-band co-axial cables are used for digital
transmission whereas Broadband co-axial cables are used for analog transmission.

Fiber-optic cable: It is a thin thread of glass that transmits lively beams of light rather than electric current. Fiber-optic
cable can carry data at a higher speed. Fiber-optic cable is immune to the electromagnetic interference. Normally in
fiber optic cable light moves only in one direction (single mode). For two-way communication (Multi-mode) to take place
a second connection must be made. Now-a-days it can support speed of more than 2 Gbps. Fiber-optic cables are used
for MAN. It is difficult to install and very expensive.

5. NETWORK HARDWARE
Modem
 The term modem is derived from 2 terms Modulator & Demodulator.
 Modulator means converting digital signals into analog signals & Demodulator means converting Analog signals
into digital signals.
 On sending computer Modem works as modulator whereas on the receiving computer Modem works as a
demodulator.
 Modem is capable of doing both but it will work as a modulator or demodulator depending on where you are
using a Modem.
 Modem is required if data is transferred over a telecommunication line.
 Modem can be either internal/external.
 Diagram for Data communication between Computerl (CI) and Computer2 (C2) using telecommunication line will
be as follows:

MAC Address
 In computer networking, a Media Access Control address (MAC address) is a unique 48- bit number assigned to
Network Interface Card (NIC) to identify it on a LAN.
 Because they are so long, MAC addresses are usually displayed in hexadecimal.
 This address is stored in its hardware, such as the card's read-only memory.

Hubs
 Hub is a hardware device that provides a common connection point in LAN.
 Hub is connected to Server and each node is connected to the hub by means of simple twisted pair wires.
 A simple network device that connects other devices to the network and sends packets to all the devices
connected to it.
 Hub contains multiple ports.
 Hubs cannot filter data, so data packets are sent to all connected devices.
 There are 3 types of Hub viz. Passive Hub, Active Hub and Intelligent Hub.
Switch
 Switches are combination of hardware and software devices, which are used to direct messages across a
network.
 A network device that connects multiple devices together and filters packets based on their destination with the
connected devices.
 Switch can read MAC address therefore, it will transfer data to the correct device's but not to all the connected
devices.
 Switches create temporary point to point links between two nodes on a network and send all data along that
link.
 Hub/Switch is basically used to create a network.
 Basically, Hub and Switch is used for the same purpose but difference is that switch can read MAC address of the
device therefore it will transfer data to correct device's whereas Hub cannot read MAC address of the device
and therefore it will transfer data to all the devices.

Bridge
 Bridge is collection of Hardware & Software facilities, which enables devices on one network to communicate
with devices on another, similar Network.
 Bridge is a communications processor that connects two Local Area Networks (LANS) working on the same
protocol.
 The main task of a bridge computer is to receive and pass data from one LAN to another.
 A bridge is a repeater with add on functionality of filtering contents by reading the MAC addresses of source and
destination.
 Bridges do not provide management facilities.

Router
 A device that receives and analysis packets and then routes them towards their destination.
 In some cases, a router will send a packet to another router; in other cases, it will send it directly to its
destination.
 Routers are required on Internet to read IP addresses.
 If IP-address is of our network then the packet is transferred to our network else the packet is forwarded to next
router on Internet.
 Router is used to connect the networks.

6. NETWORK PROTOCOLS
Each network requires protocol, which is set of rules for two devices to communicate
Transmission Control Protocol/Internet Protocol (TCP/IP)
A set of networking protocols widely used on the Internet that provides communications across interconnected
networks of computers with dissimilar hardware architectures and various operating systems. TCP/IP includes standards
for how computers communicate and conventions for connecting networks and routing traffic.

TCP/IP has four layers:


i. The Application Layer which provides services directly to the users such as E-mail, File Transfer etc.
ii. The Transport Layer which provides end-to-end communication between applications and verifies correct packet
arrival.
iii. The Internet Layer which provides packet routing for Error checking. Addressing and Integrity.
iv. The Network Interface Layer provides an interface to the network hardware.
Application Layer SMTP FTP DNS
Transport Layer SCTP TCP UDP
Internet Layer IP
Network Interface Layer MAN LAN WAN

SCTP: System Control Transmission Protocol. Used for Internet telephony and related applications.
UDP: User Datagram Protocol. Used for connectionless TCP/IP transport layer. TCP/IP creates a packet-switching
network. When a message, whether it is a file or just e-mail, is ready to be sent over the Internet, the TCP protocol
breaks it up into small packets. Each packet is then given a header, which contains the destination address. The packets
are then sent individually over the Internet. The IP protocol guides the packets so that they arrive at the proper
destination. Once reached at destination, the TCP resembles the packets into the original message,

Open System Interconnection (OSI) Model


 An ISO (International Standards Organisation) standard that covers all aspects of network communications is the
Open Systems Interconnection (OSI) model.
 An open system is a set of protocols that allows any two different systems to communicate regardless of their
architecture.
 The purpose of the OSI model is to show how to facilitate communication between different systems without
changing the hardware or software.
 The OSI model is not a protocol; it is a model for understanding and designing a network architecture that is
flexible, robust and interoperable.
 There are seven layers in OSI model are as follows:
Layer (Number) Duties of Layer
Application (7) To provide services to users.
Presentation (6) To translate, encrypt and compress data.
Session (5) To establish, manage and terminate session.
Transport (4) To deliver a message from one process to another process.
Network (3) To move packets from source to destination.
Data Link (2) To organize bits into frames.
Physical (1) To transmit bits over a medium; to provide mechanical and electrical specifications.
Note: Layer 7, 6 and 5 are called as Upper Layers; the remaining Layers are called as Lower Layers.

7. INTERNET
Website
 A website is a digital presence on the internet, accessible through a web browser.
 It is built using HTML (Hypertext Markup Language) for content structure and CSS (Cascading Style Sheets) for
presentation and layout.
 Comprises interconnected web pages that may include text, images, videos, and other multimedia elements.
 Identified by a unique domain name (e.g., www.example.com) that serves as its address on the web.
 Website files are hosted on web servers, making the content accessible globally.
 Typically includes a navigation system allowing users to move between different pages and sections.
 May incorporate interactive elements like forms, buttons, and links to engage users.
 Serves a specific purpose, such as providing information, selling products, sharing content, or facilitating
communication.
 Ideally designed to be responsive, adapting to different screen sizes for optimal viewing on various devices.
 Implementing security measures to protect data and ensure safe user interactions.

E-mail
 E-mail, short for electronic mail, is a method of exchanging digital messages over the internet.
 Requires users to have an email account, typically provided by email service providers like Gmail, Outlook, or
Yahoo.
 Messages are sent to and from specific email addresses, formatted as [email protected].
 Comprises a subject line for summarizing the message and a body where users can write the main content.
 Allows users to attach files, documents, or media to their emails for sharing additional information.
 Organizes emails into folders or labels to manage and categorize messages.
 Emails are stored in the inbox when received and in the sent items when sent, creating a record of
communication.
 Supports carbon copy (CC) and blind carbon copy (BCC) for including additional recipients with or without
others' knowledge.
 Enables users to reply to received emails or forward them to other recipients.
 Includes spam filters to automatically identify and move unwanted or suspicious emails to a separate folder.
 Users can set up a signature, typically at the end of their emails, containing personal information or professional
details.
 Some email services offer encryption options to enhance the security and privacy of email communication.
Sniffing
 Sniffing is a network monitoring technique used to capture and analyze data packets transmitted over a
network.
 Involves intercepting and inspecting data packets as they travel across a network, revealing the information
being exchanged.
 Sniffers operate in promiscuous mode, allowing them to capture and analyze all network traffic, not just the
packets intended for the device.
 Analyzes the content and structure of packets to understand the communication protocols being used, such as
HTTP, FTP, or SMTP.
 In some contexts, sniffing can be used for unauthorized access, capturing sensitive information like usernames,
passwords, or other confidential data.
 Legitimate use includes network troubleshooting and monitoring to identify issues, analyze performance, and
optimize network configurations.
 Unauthorized or malicious sniffing poses a security threat, as it can lead to the exposure of sensitive information
and compromise the confidentiality of data.
 Sniffing becomes more potent when applied to unencrypted communication, as encrypted data is more
challenging to intercept and interpret.
 Sniffing is particularly relevant in wireless networks, where it can capture data transmitted over the airwaves.

Spoofing
 Spoofing involves deceptive techniques where an entity disguises its identity to appear as someone else or as a
trusted source.
 In network security, IP spoofing occurs when an attacker alters the source IP address in a network packet to
make it appear as if it comes from a trusted source.
 In emails, spoofing occurs when the sender's address is manipulated to appear as if the message is from a
different source, often to trick the recipient.
 In telecommunication, caller ID spoofing involves manipulating the caller ID information to display a different
number than the actual one.
 This type of spoofing involves altering the Domain Name System (DNS) responses to redirect users to malicious
websites by providing false IP addresses.
 In computer networks, MAC spoofing entails changing the Media Access Control (MAC) address of a device to
impersonate another device on the network.
 In the context of biometrics, spoofing refers to tricking a system by presenting fake biometric data, such as
fingerprints or facial features.
 Spoofed websites mimic legitimate sites to deceive users into providing sensitive information, often part of
phishing attacks.
 Security measures like encryption, digital signatures, and multi-factor authentication are implemented to
mitigate the risks associated with various types of spoofing.
 Spoofing poses a significant security threat by undermining trust, leading to potential unauthorized access, data
theft, or other malicious activities.

8. Types of Hackers
1. White Hat Hackers:
 Ethical hackers who use their skills to help organizations identify and fix security vulnerabilities.
 Often employed by companies to perform penetration testing and strengthen cybersecurity.

2. Black Hat Hackers:


 Malicious hackers who exploit vulnerabilities for personal gain, unauthorized access, or to cause harm.
 Engage in activities such as data theft, financial fraud, or disruption of services.
3. Grey Hat Hackers:
 Operate between white hat and black hat hackers, as they may exploit vulnerabilities without permission but
with the intent to notify the affected party.
 Intentions can vary, and actions may be for ethical reasons or personal curiosity.

4. Hacktivists:
 Hackers motivated by social or political causes, aiming to promote their ideologies or protest against specific
issues.
 Often engage in cyber-attacks as a form of digital activism.

5. Script Kiddies:
 Inexperienced individuals who use pre-written scripts or tools to carry out hacking activities without deep
technical knowledge.
 Typically motivated by a desire to gain recognition or cause disruptions.

6. State-Sponsored Hackers:
 Operate on behalf of a government or state entity with the intent of espionage, cyber warfare, or political
influence.
 Engage in sophisticated and targeted attacks against other nations or entities.

7. Hacktivist Groups:
 Collective of hackers with shared ideological or political goals, working together to achieve their objectives.
 Examples include groups like Anonymous, who often target organizations or governments.

8. Cyber Criminals:
 Individuals or groups primarily motivated by financial gains, engaging in activities such as ransomware attacks,
identity theft, or credit card fraud.

9. Insider Threats:
 Employees or individuals with internal access to systems who misuse their privileges for malicious purposes.
 Can pose a significant threat due to their knowledge of internal systems.

10. Organized Cybercrime:


 Criminal organizations with a structured hierarchy engaging in sophisticated cyber-attacks for financial gains.
 Often involved in activities such as cyber extortion, hacking for hire, or selling stolen data on the dark web.

9. SEARCHES
SEARCH ENGINES: A search engine is a program or web page on a web site that helps you to search an Internet site or
the entire Internet for a specific key word or words. The search engine then displays a list of Web pages that contain
information related to the key word/s. Search engines are also called as Web crawlers or spiders.

Examples: google.com, yahoo.com, msn.com, inditimes.com, inforseek.com, alvavista.digital.com etc.

ADVANCE SEARCH: To overcome the problems of duplicate and irrelevant results, many search engines provide a set of
advanced search options. Advance search is possible (by clicking at Advance Search option) with search engine. In
advance search user can type key words which should be present, key words which should not be present. Also user can
select Result per page, Language, File type etc.
BOOLEAN SEARCH: Most of the search engines allow special words, called Boolean operators. Boolean operators are
used to modify your search condition. Boolean operators are AND, OR, NOT. You can use these Boolean operators along
with key words in the search text box. Many search engines use implied Boolean operators by default. Some of them will
use OR as default Boolean operator whereas, some of them will use AND as default Boolean operator. It is better
practice to use Boolean Operator in your search condition. Boolean operators are not supported by some search engines
in that case you can use advance search.

META SEARCH ENGINES: The Meta search engine is software which can search through many Internet search engines
simultaneously. The user search request is sent to number of search engines like google, msn, indiatimes, yahoo, etc.
The user can check the results obtained from the multiple searches and then connect to any web page he wants.

Every search engine has a specific format in which it should receive the search request. The Meta search engine knows
the exact format required by every search engine therefore it will forward the search request in proper format to the
search engine. The advantage of the Meta search engine is that the user does not have to know the formats of the
different search engines.

Examples: metasearch.com, metacrawler.com, mamma.com, dogpile.com......

MYSQL
1. Write MySQL statement to create a table called BEST having the columns Consumer Number (CNO, integer, Primary
key), Consumer Name (CNAME, character with variable width 30 columns). Type of connection (TYPE, character with
variable width 25 columns default value “INDUSTRIAL”) and bill amount (BILL, width of 9 including 2 decimals, positive).

MYSQL > CREATE TABLE BEST


> (CNO INT PRIMARY KEY,
> CNAME VARCHAR (30),
> TYPE VARCHAR (25) DEFAULT “INDUSTRIAL”,
> BILL DECIMAL (9,2) UNSIGNED) ;

2. Write MySQL statement to create a table called COMPANY having columns Employee Number (EN, integer, should be
increased by 1 automatically). Name of employee (NAME, character with width 30 columns). Department name (DEPT,
character with variable width 20 columns, should not be empty) Gender (GENDER, Boolean) and Provident Fund Amount
(PF, 8 integer and 2 decimals).

MYSQL > CREATE TABLE COMPANY


> (EN INT AUTO_INCREMENT PRIMARY KEY ,
> NAME CHAR (30) ,
> DEPT VARCHAR (20) NOT NULL,
> GENDER BOOLEAN,
> PF DECIMAL (10,2)) ;
3. Write MySQL statement to create a table called PAYROLL having columns Employee Number (ENO, integer, Primary
key), Employee Name (ENAME, character with variable width 25 columns, should not be empty), Date of Joining (DOJ,
Date) and Salary (SALARY, width of 9 including 2 decimals, default value 18000)

MYSQL > CREATE TABLE PAYROLL


> (ENO INT PRIMARY KEY ,
> ENAME VARCHAR (25) NOT NULL ,
> DOJ DATE ,
> SALARY DECIMAL (9,2) DEFAULT 18000) ;

4. Write MySQL statement to create a table called ABFOUNDATION having columns Donor Identity Number (DNO,
integer, Primary key), Donor Name (DNAME, character with width 20 columns), Donor Email Address (Demail, character
with width 15 columns), Amount Donated (DAMT, Integer, Not negative), Date of Donation (DT, Date)

MYSQL > CREATE TABLE ABFOUNDATION


> (DNO INT PRIMARY KEY ,
> DNAME CHAR (20) ,
> DEMAIL CHAR (15) ,
> DAMT DECIMAL (9,2) UNSIGNED ,
> DT DATE) ;

5. Create a table SAMPLE in current database with following structure


Information Column name Data type and Attributes
Employee Number Emp_no Small int, no sign, auto increase & Primary key
First Name Name Varchar(10)
Date of Birth Dob Date
Salary of Employee Sal Decimal(7,2)
MYSQL > CREATE TABLE sample
> (emp_no SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
> name VARCHAR (10) ,
> dob DATE,
> sal DECIMAL (7,2) ) ;

6. Create a table EMP in a database SBI


Information Column name Data type and Attributes
Employee Number ENO Small int, no sign, Primary key
Name Name Varchar(10)
Date of Joining DOJ Date
Age AGE Small int (Always positive)
Salary SAL Decimal (10,2)

MYSQL > USE SBI ;


MYSQL > CREATE TABLE EMP
> (ENO SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
> NAME VARCHAR (10) ,
> DOJ DATE , AGE SMALLINT UNSIGNED ,
> SAL DECIMAL (10,2) ) ;
7. Create a table MARKS in current database containing roll number (RNO, Small integer, without sign), name of a
student (SNAME, Varchar(11), Date of birth (BIRTH_DT , Date) and marks in three subjects (M1,M2,M3; All Small
integers with size 3 but without minus sign. RNO should be primary key and should increase automatically

MYSQL > CREATE TABLE MARKS


> (RNO SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY ,
> SNAME VARCHAR (11) ,
> BIRTH_DT DATE ,
> M1 SMALLINT (3) UNSIGNED ,
> M2 SMALLINT (3) UNSIGNED ,
> M3 SMALLINT (3) UNSIGNED ) ;

8. Create a table named HOSPITAL, containing information of the patient, having the columns Patient Registration
Number (PRN, should not be duplicate, Should increase automatically if value is not provided, integer),Patient name
(P_NAME, variable width 20), Age (AGE, width 2), Doctor Name ( DOCTOR, Variable Width 10, must contain some data),
Type of patient (TYPE, Character, width 3, default value OPD) and charges (CHRGS, Integer, Default 1000).

mysql > CREATE TABLE hospital


> (prn SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY ,
> p_name VARCHAR (20) ,
> age SMALLINT (2) ,
> doctor VARCHAR (10) NOT NULL ,
> type CHAR (3) DEFAULT OPD ,
> CHRGS DECIMAL (7, 2) DEFAULT 1000 ) ;

This statement is used to add new column to an existing table, to change the type or size or attribute, to change the
column name, and to delete a column. This command has 4 options
ADD, MODIFY, CHANGE and DROP

1. To add a column NET_SAL at the end of SAMPLE table.


2. To add a column designation (DESG) after the name column in SAMPLE table.
3. To add a column ID before emp_no column in SAMPLE table.
4. To add a column date of joining (DOJ) before DOB.

1. MYSQL > ALTER TABLE SAMPLE ADD NET_SAL DECIMAL(8,2) ;


2. MYSQL > ALTER TABLE SAMPLE ADD DESG VARCHAR(12) AFTER NAME ;
3. MYSQL > ALTER TABLE SAMPLE ADD ID SMALLINT UNSIGNED FIRST ;
4. MYSQL > ALTER TABLE SAMPLE ADD DOJ DATE AFTER NAME ;

1. To change the type of SAL column to decimal (8,2) from SAMPLE table.
2. To change the type of name column to clear(10) from SAMPLE table.
3. To give default value 10,000 to a salary column from SAMPLE table.
4. To change size of SNAME column to 9.

1. MYSQL > ALTER TABLE SAMPLE MODIFY SAL DECIMAL(8,2) ;


2. MYSQL > ALTER TABLE SAMPLE MODIFY NAME CHAR(10) ;
3. MYSQL > ALTER TABLE SAMPLE MODIFY SAL DECIMAL(8,2) DEFAULT 10000 ;
4. MYSQL > ALTER TABLE SAMPLE MODIFY SNAME VARCHAR (9) ;
1. To change name of a column DOB to B_DT from a table SAMPLE.
2. To change the column name SNAME to SUR_NAME.
3. To change the column name SAL to SALARY with default value as 10000 and to remove the UNSIGNED argument.

1. MYSQL > ALTER TABLE SAMPLE CHANGE DOB_DT DATE ;


2. MYSQL > ALTER TABLE SAMPLE CHANGE SNAME SUR_NAME VARCHAR (9) ;
3. MYSQL > ALTER TABLE SAMPLE CHANGE SAL SALARY DECIMAL (7,2) DEFAULT 10000 ;

1. To remove a column SALARY from a table SAMPLE.


2. Delete a column called AGE from SAMPLE table.

1. MYSQL > ALTER TABLE SAMPLE DROP SAL ;


2. MYSQL > ALTER TABLE SAMPLE DROP AGE ;

MYSQL BUILT IN FUNCTION


STRING FUNCTIONS
LCASE / LOWER : It returns the string with all alphabets changed to lowercase, other characters remains as it is.
e.g. mysql > SELECT LOWER ( ‘ MySQL ’ ) ;  mysql

UCASE / UPPER : It returns the string with all alphabets changed to uppercase, other characters remains as it is.
e.g. mysql > SELECT UPPER ( ‘ mysql ’ ) ;  MYSQL

LEFT : It returns the leftmost ‘n’ characters from the string. If ‘n’ is zero or negative then empty string is returned.
e.g. mysql > SELECT LEFT ( ‘ DATABASE ’ , 4 ) ;  DATA

RIGHT : It returns the rightmost ‘n’ characters from the string. If ‘n’ is zero or negative then empty string is returned.
e.g. mysql > SELECT RIGHT ( ‘ DATABASE ’ , 4 ) ;  BASE

SUBSTRING / MID : It returns the substring of ‘n’ characters long from given string, starting at position ‘m’.
e.g. mysql > SELECT SUBSTRING ( ‘ COMPUTER ’ , 2 , 4 ) ;  OMPU

LTRIM : It returns the string with leading (starting) removed.


e.g. mysql > SELECT LTRIM ( ‘ bbXY ’ ) ;  XY

RTRIM : It returns the trailing (ending) space removed.


e.g. mysql > SELECT RTRIM ( ‘ XYbb ’ ) ;  XY

TRIM : It returns the string with all removed string i.e. leading & trailing both.
e.g. mysql > SELECT TRIM ( ‘ bbXYbb ’ ) ;  XY

LENGTH : It returns the length of a string. i.e. number of characters within a string.
e.g. mysql > SELECT LENGTH ( ‘ abcd ’ ) ; 4

REVERSE : It returns the string in the reverse order of the characters.


e.g. mysql > SELECT REVERSE ( ‘ data ’ ) ;  atad

CONCAT : It returns the string by concatenating the arguments given in the function. Returns NULL if any
argument is NULL.
e.g. mysql > SELECT CONCAT ( ‘ My ’ , ‘ S ’ , ‘ QL ’ ) ;  MySQL
CONCAT_WS : It returns the string by concatenating the arguments with given separator. Returns NULL if separator is
NULL.
e.g. mysql > SELECT CONCAT_WS ( ‘ - ’ , ‘ My ’ , ‘ S ’ , ‘ QL ’ ) ;  My-S-QL

NUMERIC FUNCTIONS
ABS : It returns the absolute value of X. If X is negative then it is multiplied by -1 otherwise X remains as it is.
e.g. mysql > SELECT ABS ( -2 ) ; 2

MOD : It returns the remainder of N divided by M. Answer will have sign of N.


e.g. mysql > SELECT MOD ( 34 , 10 ) ; 4

ROUND : It returns the argument X, rounded to a number with D decimals. If D is 0, result will be without decimal point.
If D is negative, ‘ -1’ then nearest 10, ‘-2’ nearest 100 etc.
e.g. mysql > SELECT ROUND ( 1.298 , 1 ) ; 1.3

POW / POWER : It returns the value of X raised to the power of Y.


e.g. mysql > SELECT POW ( 2 , 2 ) ; 4

SQRT : It returns the non-negative square root of X. If X is negative then answer is NULL.
e.g. mysql > SELECT SQRT ( 16 ) ; 4

DATE & TIME FUNCTIONS


DAY : It returns the day of the month for a given date, in the range 1 to 31.
e.g. mysql > SELECT DAY ( ‘ 2022-11-25 ’ ) ;  25

MONTH : It returns the month of the year for a given date, in the range 1 to 12.
e.g. mysql > SELECT MONTH ( ‘ 2022-11-25 ’ ) ;  11

YEAR : It returns the year for date, in the range 1000 to 9999.
e.g. mysql > SELECT YEAR ( ‘ 2022-11-25 ’ ) ;  2022

DAYNAME : It returns the name of the weekday for a given date.


e.g. mysql > SELECT DAYNAME ( ‘ 2022-11-25 ’ ) ;  FRIDAY

MONTHNAME : It returns the name of the month for a given date.


e.g. mysql > SELECT MYONTHNAME ( ‘ 2022-11-25 ’ ) ;  NOVEMBER

CURDATE / CURRENT_DATE : It returns the current date as a value in ‘YYYY-MM-DD’ format.


e.g. mysql > SELECT CURDATE ( ) ;  2022-11-25

NOW / SYSDATE : It returns the current date and time in ‘YYYY-MM-DD HH:MM:SS’.
e.g. mysql > SELECT NOW ( ) ;  2022-11-25 10:30:00

TIME : It returns the time part from the given date-time expression in ‘HH:MM:SS’.
e.g. mysql > SELECT TIME ( ‘ 2022-11-25 10:30:00 ’ )  10:30:00

DATE : It returns the date part from the given date-time expression in ‘YYYY-MM-DD’.
e.g. mysql > SELECT DATE ( ‘ 2022-11-25 10:30:00 ’ ) ;  2022-11-25

You might also like