- 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
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
548 Views
To write stored procedure to insert data into a table, at first you need to create a table −mysql> create table insertDataUsingStoredProcedure -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (0.51 sec)Following is the query to write stored procedure to insert data into the table −mysql> DELIMITER // mysql> CREATE PROCEDURE StoredProcedureInsertData(IN StudentName varchar(100), IN StudentAge int) -> BEGIN -> insert into insertDataUsingStoredProcedure(Name, Age) values (StudentName, StudentAge ); -> END -> // Query OK, 0 ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
383 Views
To get the max value, use the max() function. Let us create a table first −mysql> create table findMaxValueInVarcharField -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value varchar(200) -> ); Query OK, 0 rows affected (1.09 sec)Following is the query to insert some records in the table using insert command −mysql> insert into findMaxValueInVarcharField(Value) values('200'); Query OK, 1 row affected (0.14 sec) mysql> insert into findMaxValueInVarcharField(Value) values('1000'); Query OK, 1 row affected (0.25 sec) mysql> insert into findMaxValueInVarcharField(Value) values('899474'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
3K+ Views
To set delay, you can use SLEEP(). Let us implement SLEEP() in the procedure execution delay.First, we will create a stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE delayInMessage() -> BEGIN -> SELECT SLEEP(20); -> SELECT "AFTER SLEEPING 20 SECONDS, BYE!!!"; -> END -> // Query OK, 0 rows affected (0.30 sec) mysql> DELIMITER ;Now you can call the stored procedure with the help of CALL command. Following is the syntax −CALL yourStoredProcedureName();Following is the query to call the above-stored procedure and check the execution delay −mysql> call delayInMessage();This will produce the following output −+-----------+ ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
37 Views
Yes, we can do that. To understand, let us first create a table −mysql> create table enforceCompoundUniqueness -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(40) NOT NULL, -> StudentMobileNumber varchar(12) NOT NULL, -> UNIQUE StudentName_StudentMobileNumber(StudentName, StudentMobileNumber) -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert records in the table using insert command −mysql> insert into enforceCompoundUniqueness(StudentName, StudentMobileNumber) values('Larry', '2322245676'); Query OK, 1 row affected (0.18 sec) mysql> insert into enforceCompoundUniqueness(StudentName, StudentMobileNumber) values('Larry', '2322245676'); ERROR 1062 (23000): Duplicate entry 'Larry-2322245676' for key 'StudentName_StudentMobileNumber' ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
195 Views
In order to show some columns, use NOT IN and set those columns which you do not want to display. Let us first create a table. Following is the query −mysql> create table student_Information -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(50), -> StudentAge int, -> StudentAddress varchar(100), -> StudentAllSubjectScore int -> ); Query OK, 0 rows affected (0.69 sec)Following is the query to display a description about the above table −mysql> desc student_Information;This will produce the following output −+------------------------+--------------+------+-----+---------+----------------+ | Field ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
334 Views
To select min and max value from the part of a table in MySQL, use the following syntax −select min(yourColumnName) as yourAliasName1, max(yourColumnName) as yourAliasName2 from (select yourColumnName from yourTableName limit yourLimitValue) tbl1;Let us first create a table. Following is the query −mysql> create table MinAndMaxValueDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value int -> ); Query OK, 0 rows affected (0.52 sec)Insert records in the table using insert command. Following is the query −mysql> insert into MinAndMaxValueDemo(Value) values(10); Query OK, 1 row affected (0.16 sec) mysql> insert into MinAndMaxValueDemo(Value) ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
534 Views
To merge two tables with UNION, you can use create table select statement. Following is the syntax −create table yourNewTableName select * from yourFirstTableName UNION select * from yourSecondTableName;Let us first create a table. Following is the query −mysql> create table FirstTable -> ( -> Id int, -> PersonName varchar(20) -> ); Query OK, 0 rows affected (2.10 sec)Following is the query to insert some records in the table using insert command −mysql> insert into FirstTable values(10, 'Larry'); Query OK, 1 row affected (0.12 sec) mysql> insert into FirstTable values(20, 'David'); Query OK, 1 row ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
155 Views
To compare two strings, which are numbers, let us first create a table. Following is the query −mysql> create table compareTwoStringsDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command −mysql> insert into compareTwoStringsDemo(Value) values('1235667'); Query OK, 1 row affected (0.66 sec) mysql> insert into compareTwoStringsDemo(Value) values('999999'); Query OK, 1 row affected (0.11 sec) mysql> insert into compareTwoStringsDemo(Value) values('999888'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
76 Views
Use the CURRENT_TIMESTAMP instead of current_date() in MySQL for timestamp default current_date. Let us first create a table. Following is the query −mysql> create table defaultCurrent_DateDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.55 sec)Following is the query to insert some records in the table using insert command −mysql> insert into defaultCurrent_DateDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.52 sec) mysql> insert into defaultCurrent_DateDemo(StudentName, StudentAdmissionDate) values('Chris', '2019-01-31'); Query OK, 1 row affected (0.18 sec)Following is the ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
105 Views
To view the auto_increment value for a table, you can use INFORMATION_SCHEMA.TABLES.Let us first create a table −mysql> create table viewtheauto_incrementValueForATableDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.84 sec)Following is the query to insert some records in the table using insert command −mysql> insert into viewtheauto_incrementValueForATableDemo(StudentName) values('Ramit'); Query OK, 1 row affected (0.23 sec) mysql> insert into viewtheauto_incrementValueForATableDemo(StudentName) values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into viewtheauto_incrementValueForATableDemo(StudentName) values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> ... Read More