blogspot visit counter
Showing posts with label MySql. Show all posts
Showing posts with label MySql. Show all posts

Thursday, 24 October 2013

How to Change Table Name in MySQL

Introduction :-
If you want to change the Table name without loss you data then it's very simple to change the table in MySQL database and sql server database.

Description : -

To change the name of an existing table first to second, use this command as shown below


RENAME TABLE first TO second;

For Example

You have table name like stodent_tab
and there are four fields like First_name,Last_Name,Stud_ID,Stud_Batch
and you want to change the name of  stodent_tab because you have done mistake in student_tab name

So Query Like This


RENAME TABLE stodent_tab TO student_tab;

Note -: This query is same if you want to use the sql server database.

Wednesday, 18 September 2013

Timestamp in mysql

Timestamp in mysql
TimeStamp : -
The TIMESTAMP data type is the only way to have MySQL automatically set the time when a row was inserted and/or updated. DATETIME columns can’t do this.
TIMESTAMP columns are identical to DATETIME columns with one important exception — they can be set to take the current time value when a row is created or updated.


Note  -  If you want to use a timestamp  column then  set Defalut as shown



create table using timestamp as shown below

CREATE TABLE IF NOT EXISTS `user_tab` (
  `x` varchar(200) NOT NULL,
  `y` varchar(200) NOT NULL,
  `id` varchar(200) NOT NULL,
  `usertime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)

GUI  structure as  shown below





Note - if you set defaut  as a timestamp then don not use the time stamp column name at the time of insertion  it automaticlay insert the time in timestamp column

Wednesday, 28 August 2013

How to Change a Column Name in MySQL

How to Change a Column Name in MySQL
Introduction : -
In this article i am explain how i can change the column name of MySQL database table

Description :-

This is very to change the table column name in mysql database.
I have a info_tab (this is table name). And  id , user_id, Fisrt_Name, LastName

table as shown below




alter table info_tab change First_Name2 First_name varchar(30)

Here info_tab is table name 
First_Name2  is  old column name  which you want to change
Fist_Name Is new Column name  of the table

Tuesday, 25 June 2013

How i can use like keywords in mysql

How i can use like keywords in mysql
Introduction : -

The LIKE operator is commonly used to select data based on patterns. Using the LIKE operator in appropriate way is essential to increase the query performance.

The LIKE operator allows you to select data from a table based on a specified pattern. Therefore the LIKE operator is often used in the WHERE clause of the SELECT statement.

MySQL provides two wildcard characters for using with the LIKE operator, the percentage % and underscore _.

1 : - The percentage ( %) wildcard allows you to match any string of zero or more characters.
2 : - The underscore ( _) wildcard allows you to match any single character.

Example of  MySQL Like

Suppose We Have Table  Like this


Suppose you want to search for file_upload_tab whose first name starts with character ‘ p‘, you can use the percentage wildcard ( %) at the end of the pattern as follows:

SELECT apk_nm,file_url FROM file_upload_tab  WHERE file_url like 'p%'

Oupput as shown below


To search for file_url  whose last name ends with ‘up‘ string e.g., Patterson, Thompson, you can use the % wildcard at the beginning of the pattern as the following query:

Query -:
SELECT apk_nm,file_url FROM file_upload_tab  WHERE apk_nm like '%up'

OutPut as shown below



If you want to search column whose last values is .jad then we use this query

Query is - :

SELECT apk_nm,file_url FROM file_upload_tab  WHERE file_url like '%.jar%

Output as shown below



Related Posts Plugin for WordPress, Blogger...