Saturday, January 29, 2011

To get the second record on mysql

 

To get the second record on mysql you can use LIMIT and OFFSET.

Syntax:

SELECT col FROM tbl LIMIT 1 OFFSET 1;

Example:

SELECT * FROM employer LIMIT 1 offset 2;

second record on mysql

To get Third record in Mysql

Syntax:

SELECT col FROM tbl LIMIT 1 OFFSET 2;

Example:

SELECT * FROM employer LIMIT 1 offset 2;

Third ecord on mysql

Thursday, January 27, 2011

SQL to Select a random row from a database table

 

There are lots of ways to select a random record or row from a database table. Here are some example SQL statements.

Select a random row with MySQL:

Syntax:

SELECT * FROM TABLE_NAME ORDER BY RAND() LIMIT 10;

Select a random row with MySQL

Select a random row with Microsoft SQL Server:

Syntax:

SELECT TOP 1 column FROM table ORDER BY NEWID()

random_row_ Microsoft_SQL_Server

Select a random record with Oracle:

SELECT column FROM ( SELECT column FROM table ORDER BY dbms_random.value ) WHERE rownum = 1;

random_row_Oracle

Sunday, January 23, 2011

Create User in Mysql

 

MySQL offers for protecting data in the tables against deliberate or accidental unauthorized use: SQL users, passwords,and privileges.

New SQL users are not allowed to access tables belonging to other SQL users,not even with the SELECT statement. Nor can they immediately create their own tables. New SQL users must explicitly be granted privileges. We can indicate, for example, that an SQL user is allowed to query a certain table or change specific columns of a table. Another SQL user might be allowed to create tables, and another user might be allowed to create and remove complete databases.

ADDING AND REMOVING USERS

DEFINITION
<create user statement> ::=
CREATE USER <user specification>
[ , <user specification> ]...
<user specification> ::=
<user name> [ IDENTIFIED BY [ PASSWORD ] <password> ]
<user name> ::=
<name> | '<name>' | '<name>'@'<host name>'
<password> ::= <alphanumeric literal>

In a CREATE USER statement, a user name and a password are entered. In most
SQL products, the user name and password are just names consisting of letters and
numbers.
Example 28.1: Introduce two new users: SIVA with the password SIVASEC
and GANESH with the password LUAP.


CREATE USER
'SIVA'@'localhost' IDENTIFIED BY 'SIVASEC',
'GANESH'@'localhost' IDENTIFIED BY 'LUAP'


Explanation: Behind the user name, the term localhost is specified. This term
specifies the host from which the user creates a connection with MySQL. We return
to this topic later. If the name of a user or host contains special characters, quotation
marks must be placed before and after it—for example 'SIVA'@'localhost'
or 'SIVA'@'xxx.r20.com'. Quotation marks must always be placed before and
after the password.

 

create user

DROP USER statement to remove users from the system, and all their privileges are also removed automatically.

DEFINITION
<drop user statement> ::=
DROP USER <user name> [ , <user name> ]...
<user name> ::=
<name> | '<name>' | '<name>'@'<host name>'

Drop the user SIVA

DROP USER SIVA

If the removed user has created tables, indexes, or other database objects, they
remain because MySQL does not register who created the objects.

Wednesday, January 5, 2011

Saturday, January 1, 2011

Inserting XML Through Bulk Load

Inserting XML Through Bulk Load

XML Bulk Load allows you to load semistructured XML data into Microsoft SQL Server.
You can insert XML data into a SQL Server database by using an INSERT statement and the OPENXML function. This bulk load utility provides higher performance when you need to insert large amounts of XML data.

CREATE TABLE bulktable1(XmlCol xml)
go

-- One row affected (one or multiple nodes)
INSERT into bulktable1(XmlCol)
SELECT *
FROM OPENROWSET(Bulk 'C:\xmltype\demo\SampleData2.txt',
           SINGLE_CLOB) as x
go


import_xml_sqlserver


















The input Xml file is

input xml file

Working with XML Data in SQL Server 2005

Working with XML Data in SQL Server 2005

XML is one of the data types in SQL Server 2005.The XML data type lets the user to store XML data in the SQL Server database.