Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Prime Number From a Table

Write a pl/sql source code to check all data from a student_id column of a student table. After check show all student_id which are prime.


Hits: PL/SQL code with Table/View

SQL> create table studentt
2 (
3 student_id number(10),
4 student_name varchar(20)
5 );

Table created.


SQL> insert into studentt
2 values
3 (5,'aaa');

1 row created.


SQL> declare
2 a number(10);
3 b number(10);
4 c number(10):=1;
5 begin
6 select student_id into a from studentt;
7 for b in 2..a/2 loop
8 if (a mod b)=0 then
9 c:=0;
10 exit;
11 end if;
12 end loop;
13 if(c=1)then
14 dbms_output.put_line('student_id is a prime number');
15 else
16 dbms_output.put_line('student_id is not a prime number');
17 end if;
18 end;
19 /

Prime Number From a Table

Write a pl/sql source code to check all data from a student_id column of a student table. After check show all student_id which are prime.


Hits: PL/SQL code with Table/View

SQL> create table studentt
2 (
3 student_id number(10),
4 student_name varchar(20)
5 );

Table created.


SQL> insert into studentt
2 values
3 (5,'aaa');

1 row created.


SQL> declare
2 a number(10);
3 b number(10);
4 c number(10):=1;
5 begin
6 select student_id into a from studentt;
7 for b in 2..a/2 loop
8 if (a mod b)=0 then
9 c:=0;
10 exit;
11 end if;
12 end loop;
13 if(c=1)then
14 dbms_output.put_line('student_id is a prime number');
15 else
16 dbms_output.put_line('student_id is not a prime number');
17 end if;
18 end;
19 /

DAY 2: DBMS



DBMS:
Database management System is software, which is use for maintaining Database. Database System supports single-user and multiples-user environment. While one hand DBMS permits only one person to access the Database at a given time on the other hand RDBMS allows many users simultaneous access to the Database. A Database System consists of two parts namely, Database Management System and Database Application. Database Management System is the program that Organizes and maintains the information whereas the Database Application is the program that lets us view, retrieve and update information stored in the DBMS.



Entity:
An entity is any object, place, person, concept or activity about which an enterprise records Data.
Attributes:
 An attribute is the characteristic property of an existing entity. Consider for an example:

Student id
Name
Course
001
Akash
Cse 1101
002
Mou
Cse 1102

DAY-1: DEFINITION



What is Database?

A database is a collection of information organized into interrelated tables of data and specifications of data objects. Databases are designed to offer an organized mechanism for storing, managing and retrieving information. They do so through the use of tables. Database tables consist of columns and rows. Each column contains a different type of attribute and each row corresponds to a single record. For example, imagine that we were building a database table that contained Student_id, Name, Program_id, City, Division and Country.

Then we have simply start adding rows underneath those columns that contained the data we were planning to store. See the below schema and data table as per above discussion. This example will clear your concept of the relation between schema and data tables.

Schema:
Entity/Field Name
Data-Type
Student_id
Number(10)
Name
Varchar2(30)
Program_id
Varchar2(15)
City
Varchar2(15)
Division
Varchar2(15)
Country
Varchar2(15)







                                                            Schema: 1

The above schema explains that the student_id must be number data type and it will take up to 10 (ten) digit. So, greater then or equal to 11 (eleven) digit numeric value will not accept as a Student_id.  The Name field will accept maximum 30 (thirty) character. And all the remaining entity will follow rules as shown in the Data-Type Column in the above schema. Schema represents the physical infrastructure of a database table where we may keep our necessary data.

Data Table:

Student_id
Name
Program_id
City
Division
Country
200819222
Adina
English
Noakhali
Chittagong
Bangladesh
200819223
Nishi
English
Noakhali
Chittagong
Bangladesh
200819224
Iasha
Physics
Bogura
Rajshahi
Bangladesh
200819225
Asha
Chemistry
Dinajpur
Rajshahi
Bangladesh
                                                            Table: 1

The above table contains some sample data. We may easily understand that the all the data kept in above table are interrelated. The data belongs to students of an Institute. We may easily understand and get some information of a particular student by examining the records. Click here to see more examples of Insert Command, which will help to you learn of insert/store Value to a table.


What is Table?

A table in a relational database is a predefined format of rows and columns that define an entity. Database tables are composed of individual columns corresponding to the attributes of the object. A database may consist of many tables. In the above schema, student is an object. Student_id, name and etc are the entity. Entities are represents in column wise.  All the values of the entity are represents row wise as like above Data-Table. So, we may say finally that table is used to keep the records.

What is Record?

A database record consists of one set of tuples (variable/entity) for a given relational table. In a relational database, records correspond to rows in each table. In a relational database, a row consists of one set of attributes (or one tuple) corresponding to one instance of the entity that a table schema describes. The Schema 1 describes the tuples of student table and the table 1 shows the data of student table which correspondence the record of each student. Each record at table 1 illustrates row wise. In simply, a collection of fields is called a record.

What is Object?

A single data item related to a database object. The database schema associates one or more attributes with each database entity.

What is Field?

In database systems, fields are the smallest units of information you can access. In spreadsheets, fields are called cells. In database management systems, a field can be required, optional, or calculated. A required field is one in which you must enter data, while an optional field is one you may leave blank. A calculated field is one whose value is derived from some formula involving other fields. You do not enter data into a calculated field; the system automatically determines the correct value.

What is Attribute?

In database management systems, the term attribute is sometimes used as a synonym for field. In database systems, a field can have various attributes. For example, if it contains numeric data, it has the numeric attribute. Most fields have certain attributes associated with them. For example, some fields are numeric whereas others are textual, some are long, while others are short. In addition, every field has a name, called the field name.

What is data?

Data is a distinct piece of information, usually formatted in a special way. All software is divided into two general categories: data and programs. In Table 1, “200819222” is found in a row (cell). It is actually data. It indicates that is an Id of a student.

What is data files ?

In database management systems, data files are the files that store the database information, whereas other files, such as index files and data dictionaries, store administrative information, known as metadata.

Now, let us concentration on the  parts of SQL, which will be path of understanding SQL commands. Click Here to Visit Day-2 for these.



DAY-1: THE SQL

What is SQL?

SQL stands for Structured Query Language. SQL is used to communicate with a database. According to American National Standards Institute, it is the standard language for relational database management systems.

SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, etc. 

However, the standard SQL commands can be used to accomplish almost everything that one needs to do with a database. This tutorial will provide you with the instruction on the basics of each of these commands as well as allow you to put them to practice using the SQL Interpreter.

SQL expression consists of three clauses: select, from, and where. A sample SQL statement that makes this query is:

SELECT * FROM STUDENT 

The most commonly used statement in SQL is the SELECT statement, which retrieves data from the database and returns the data to the user. The STUDENT table example illustrates a typical example of a SELECT statement situation. In addition to the SELECT statement, SQL provides statements for creating new databases, tables, fields, and indexes, as well as statements for inserting and deleting records. The  from clause by itself defines a Cartesian Product of the relations in the clause. Here STUDENT is the name of the relation (Entity Set/Table).

Now, Analyze the STUDENT table and SELECT statement with fundamental knowledge of Database, Table, Field from HERE.

Popular Posts