SQL tip: To get first 10 Rows from a Table and profile the columns

For people working with database tables:
Most will want to check out the columns in the table and do a quick scan to get 10 rows to sample data in the table.

Here’s the SQL syntax for doing that with some of the biggest relational database vendors.

The first query gets 10 rows from a table called ‘Students’.
The second query shows all the columns in this table.
The third query is an alternative style (if exists).

MySql Syntax

SELECT * FROM Students LIMIT 10;

# Two ways to do in mysql
DESCRIBE Students;

SELECT * FROM information_schema.columns WHERE table_name = 'Students';

Postgres syntax

SELECT * FROM Students LIMIT 10;

# this one below only works in console
d+ Students

# or
SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS where table_name = 'Students';

MicroSoft Sql Server T-Sql syntax

SELECT TOP 10 * FROM Students
GO

SELECT *
FROM information_schema.columns
WHERE table_name = 'Students'
ORDER BY ordinal_position
GO

Oracle PL/Sql syntax

SELECT * FROM Students WHERE ROWNUM <=10;

DESCRIBE Students;

Advertisements
This entry was posted in data wrangling and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s