Showing posts with label SQL Queries. Show all posts
Showing posts with label SQL Queries. Show all posts

Tuesday, June 18, 2013

Most common and basic SQL Queries of DBMS

Leave a Comment Follow us on twitter
SQL Queries as you already know from previous post is the essential of Database Management System (DBMS). In this post we are going to learn some of the very basic SQL Queries that are commonly used. Let’s see these SQL Queries one by one.


Most Commonly used SQL Queries



1. Create a Table

To create table the command used is create table. Syntax is as follows:

create table table-name(column1 datatype, column2 datatype, column3 datatype….,columnn datatype);

E.g.

create table employees(name varchar2(25), employee_id number(5), salary number(10));

2. Insert values into table

Inserting values into a table is done by using insert command. Syntax is as follows:

insert into table-name values(“value1”,value2,value3);

E.g.

insert into employees values(“John”,12545,25000);

Here the name is taken into inverted commas as except number, we use all the values into inverted commas.

3. Display Table

Display a table is quite easy. To display a table along with its all columns, select command is used. Syntax is as follows:

select * from table-name;

E.g.

select * from employees;

Running the very above command will display the whole table, that’s why * is used. To display any specific column or multiple specific columns, * is replaced by column name.

For example: select name,salary from employees;

4. Describe Table

To show the names of column along with their datatypes the command we use is desc or describe. It will show the complete description of your table. Syntax is as follows:

desc table-name; or describe table-name;

E.g.

desc employees; or describe employees;

These are some of the very common and basic SQL Queries generally used. I hope that you will be now able to understand the SQL Queries without any difficulty. If you want to practice these SQL Commands you can download Oracle 11g which is the latest edition from Oracle directly from their website. In the next post we will discuss about the constraints used in SQL Queries.
READ MORE...

Wednesday, June 12, 2013

SQL Queries in DBMS: A beginner’s guide

Leave a Comment Follow us on twitter
SQL Queries are very important part of Database Management System (DBMS). Structured Query Language is a language which led user to interact with Database Management System (DBMS). To handle and manage the database one should know about these SQL Queries. Here we are going to discuss some of the very basic and important SQL Queries which are going to help thought your life whether you are going to be a Database Administrator (DBA) or pursue a career in Database etc.

Data types used in Structured Query Language (SQL)




Most commonly the data types used in SQL are char, varchar, varchar2, number, date and long. Let’s see each of them one by one.
 
  • char: As the name implies char represents character string of maximum 255 characters. However user can specify its own limit for the variable. Syntax is variable_name char(number of characters).

E.g. country char(20)

This states that user can enter any country name having maximum of 20 characters. If the name of country contains less than 20 characters then the rest of the size will be filled with the spaces.

  • varchar: This data type is very similar to char and perform the same function as of char data type.  The difference is that varchar can take the character string of maximum 4000 characters. Unlike the char data type, varchar doesn’t pad inserted value with spaces. Syntax is variable_name varchar(number of characters).

  • varchar2: varchar2 is the advance version of varchar. There is no difference between the two, however experts says using varchar2 is better than varchar. I don’t know what the reason is.

  • number: This data type is used to store the numbers. Syntax is variable_name number(size),  where size is the maximum length of data.

E.g. addition number(4);
  • long: long data type accepts the character string maximum of 2 Giga Bytes. In normal practice we don’t use long data type.

So, these are the data types that are mostly used while performing the SQL Queries.
READ MORE...