Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Sunday, 24 May 2015

How to Fetch Sample Records From MySql Database

We can fetch sample records from MySql database by using LIMIT clause and the end of the query.

The basic syntax is:-

SELECT * FROM TABLE_NAME LIMIT ]NUMBER]

Example can be:-

SELECT * FROM EMPLOYEES LIMIT 5;

How to Fetch Top N records from SQL Database

The SQL TOP clause is used to fetch a TOP N number of records from a table.

The basic syntax is:-

SELECT TOP number|percent column_name(s)
FROM table_name
WHERE [condition if required] 

Example can be like:-

SELECT TOP 3 * FROM EMPLOYEES;

How to create database in SQL Server

To create database, You must have administrative privileges, otherwise you won't be able to create it.

When you need to create database in SQL Server then "Create Database" Statement is use.

Basic Syntax is :-

CREATE DATABASE DATABASE_NAME;

Let's Assume You need to create employees database then :-

CREATE DATABASE EMPLOYEES;

You can then see the list of databases as :-

SHOW DATABASES;

Creating DNS Entry With & Without Default Port Number For SQL Database



In day to day tasks, many times we need to connect from one database to other. To connect to other database may require ODBC (Open DataBase Connectivity) or JDBC (Java DataBase Connectivity) drivers. DNS (Domain Name System) help us to create connection to other database with the help of ODBC or JDBC drivers. 

Many times DBS's (Database Administrators) do not keep default port number of the database and they change according to the availability of the port. To connect to the database which is not having default port through DNS can be hectic if you don't have proper idea to create DNS entry.
Let's see how we can create DNS entry for the SQL Server Database.

To perform this activity, first you need to have Administrative privileges and secondly you need to have IP address of the server to which you need to connect and the port number allotted to that application. And last you need to have authorized user id and password to connect.

First of all, you need to install ODBC drivers on the machine where you need to create DNS entry. ODBC drivers can be for 32 bits or 64 bits. It is depends upon what bits your system is. There is no difference in the steps while creating DNS entry for 32 bits or 64 bits.

In my case I would be using ODBC drivers 64 bits on Windows:-

First open 64 bits ODBC administrator. You may find it on the start button or it is in the control panel of the machine. Below screen shot from the start menu:-





You may find ODBC administrator tool in Control panel on below mentioned path:-


Control Panel\All Control Panel Items\Administrative Tools

1. Open 64 bits ODBC administrator and go the System DSN tab:-

2. Clicked on Add button, "Create New Data Source" will open:-



3. Scroll below and Click on SQL server and hit Finish:-






4. It will open "Create New Data Source To SQL Server" dialog box:-


5. Type the name of the DNS entry. Write down the description for the data source. You may keep description blank. Most importantly you need to provide the server IP address to which you need to connect. Let's consider you have 00.00.00.00 IP address.























Note :-  We have not provided port number and system will take default port number.



6.  I have provided the IP address above. Hit next. Choose Login Id from SQL Server Authentication:-



















































7.  Provide the user name and password of SQL server and hit on Next:-



8. Change the default database if you need and then hit Next:-




9. Click on Finish. If everything goes Right then below Dialog box will open and show message as "Successfully Configured.". You can check out all the parameter that you have provided here.:-


10. Finally click on Test Data Source:-



































You will find the result as " Completed Successfully! "


Now, the most important part is how to configure DNS entry with particular port number?

In step 5 we have provided only server IP address and not mentioned any port number. We need to provide SQL server IP address and  ","(comma) and then port number as shown below:-


Above, Suppose my SQL server IP address is 00.00.00.00 and my port number is 1106 then I have mentioned that after writing "," (comma) and all other steps will be same.

NOTE: - COMMA is important while providing non-default port.


Please provide your feedback in the comments section above. Please don't forget to follow.