0% found this document useful (0 votes)
6 views

SQL material-3

The document provides an overview of SQL statements including the UNION operator for combining SELECT results, the creation and execution of stored procedures, the use of INSERT INTO SELECT for copying data between tables, and the AUTO INCREMENT constraint for generating unique identifiers. It includes syntax examples for each operation, such as creating tables and renaming them or their columns. Overall, it serves as a quick reference guide for basic SQL functionalities.

Uploaded by

Paramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL material-3

The document provides an overview of SQL statements including the UNION operator for combining SELECT results, the creation and execution of stored procedures, the use of INSERT INTO SELECT for copying data between tables, and the AUTO INCREMENT constraint for generating unique identifiers. It includes syntax examples for each operation, such as creating tables and renaming them or their columns. Overall, it serves as a quick reference guide for basic SQL functionalities.

Uploaded by

Paramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL statements

The UNION operator is used to combine the results of two or more SELECT statements.
Every SELECT statement within UNION must have the same number of columns, similar
data types
Union operator result will not include duplicate data.
Syntax:
SELECT column_name(s) FROM table1
UNION/UNION ALL
SELECT column_name(s) FROM table2;
Example:
select mid,mname from mobiles
union
select aid,aname from accessories;
Stored Procedure
A stored procedure is a prepared SQL code that can be saved, so the code can be reused
over and over again.
Syntax to create stored procedure:
DELIMITER //
CREATE procedure procedure name()
BEGIN
SQL query…
END
//
Syntax to execute a stored procedure:
Call procedurename;
Example:
DELIMITER //
CREATE procedure PROC111()
BEGIN
SELECT * from mobiles;
END
//
call PROC111;
INSERT INTO SELECT:
Copy all columns from one table to another table:
Syntax:
INSERT INTO table2 SELECT * FROM table1 WHERE condition;
Example:
INSERT INTO mobiles SELECT * FROM accessories;

AUTO INCREMENT constraint:


Auto-increment allows a unique number to be generated automatically when a new record is
inserted into a table.
Syntax:
create table table name(column name datatype primary key auto_increment,
columname datatype);
Example:
create table mobiles(mid int primary key auto_increment, mname varchar(10));
Rename Table:
Syntax:
RENAME TABLE old_table TO new_table;
Rename Table column:
Syntax:
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;
Example:
ALTER TABLE mobiles2 RENAME COLUMN mid TO mid1;

You might also like