- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
300 Views
Yes, we can do that. Let us first create a table −mysql> create table DemoTable( Id int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(201); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(202); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(290); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(301); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------+ ... Read More
1K+ Views
The @@identity returns the last inserted value in the auto_increment column in the current session. Let us first create a table −mysql> create table DemoTable( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName) values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(UserName) values('Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(UserName) values('Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(UserName) values('Robert'); Query OK, 1 row affected (0.24 sec) ... Read More
138 Views
Let us first create a table −mysql> create table DemoTable( ProductName varchar(100), ProductPrice int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Product-2', 78); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Product-1', 88); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Product-2', 86); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Product-1', 45); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More
372 Views
If you will extend the size of a varchar field in MySQL then it won’t affect the data inside it.Let us first create a table −mysql> create table DemoTable( Name varchar(8) ); Query OK, 0 rows affected (1.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.13 sec)Display all records from the ... Read More
55 Views
Let us first create a table −mysql> create table DemoTable( FirstName varchar(100) ); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.27 ... Read More
106 Views
For this, you can use a PREPARE statement. Let us first create a table −mysql> create table DemoTable( FirstName varchar(100), CountryName varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Chris', 'AUS'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert', 'UK'); Query OK, 1 row affected (0.32 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+-------------+ | FirstName | ... Read More
88 Views
For this, use the GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable( Name varchar(100), Age int ); Query OK, 0 rows affected (1.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 23); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('David', 21); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 23); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris', 21); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Mike', 25); Query OK, ... Read More
2K+ Views
Here we will see how to check given year is leap year or not, using PL/SQL. In PL/SQL code, some group of commands are arranged within a block of related declaration of statements.The leap year checking algorithm is like below.AlgorithmisLeapYear(year): begin if year is divisible by 4 and not divisible by 100, then it is leap year else if the number is divisible by 400, then it is leap year else it is not leap year endExampleDECLARE year NUMBER := 2012; BEGIN IF MOD(year, 4)=0 ... Read More
101 Views
For this, you need to use IN() and after that FIELD() method. Let us first create a table −mysql> create table DemoTable( StudentId varchar(10), StudentName varchar(20) ) ; Query OK, 0 rows affected (4.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10001', 'Adam'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable values('1010', 'Chris'); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable values('1020', 'Bob'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('1030', 'Carol'); Query OK, 1 row affected (0.47 sec) mysql> insert into ... Read More
1K+ Views
For exact string, you need to use wildcard ‘%’ with LIKE operator −select *from yourTableName where binary yourColumnName LIKE '%yourStringValue%';Let us first create a table −mysql> create table DemoTable( Name varchar(20) ); Query OK, 0 rows affected (1.93 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (1.11 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (1.19 sec) mysql> insert into DemoTable values('JOHN'); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable ... Read More