select * from sample_db where
id =1
and
(name like '%praveen%'
or name like '%naveen%')
SQL CONSTRAINTS
primary key
CREATE TABLE sbanks (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
TO ADD PRIMARY KEY CONSTRAINT TO EXISTING TABLE ie for one column.
syntax
ALTER TABLE sbank
ADD PRIMARY KEY (ID);
imp:u can have primary key constraint one only.
now to add primary key constraint for more than one column to already existing table with primary constraint
you have to delete existing primary key,and add new primary key constraint.
DROP a PRIMARY KEY Constraint
syntax
ALTER TABLE sbank
DROP PRIMARY KEY;
o/p
MySQL returned an empty result set
now adding primary key constraint for two columns
ALTER TABLE sbank
ADD CONSTRAINT PK_sbank PRIMARY KEY (ID,LastName)
o/p
MySQL returned an empty result set
here PK_sbank is the constraint name.
DATABASE column name search in all tables /schemas
select c.tabschema as schema_name,
c.tabname as table_name,c.colname
from syscat.columns c
inner join syscat.tables t on
t.tabschema = c.tabschema and t.tabname = c.tabname
where c.colname like '%
PRODUCT_NUMBER%' and t.type = 'T'
order by schema_name,table_name;
for more details https://dataedo.com/kb/query/db2/find-tables-with-specific-column-name
https://dataedo.com/kb/query/db2
SEARCH TABLES QUERY
select name from sysibm.systables
where name like '%ISP%'
and type = 'T'
EASY CONCATENATE STRINGS IN EXCEL AND SEARCH THE STRING IN DB
="'"&A1&"',"
DB2
SELECT * FROM customers FETCH FIRST 1 ROWS ONLY
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html?ssSourceSiteId=otnpt
SQL joins are used to
combine rows from two or more tables.
Types of Joins:
INNER JOIN: Returns all rows when
there is at least one match in BOTH tables
EG: view Intersection (matching
data in two tables) of two table’s data.
Syn:
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name;
LEFT JOIN: Return all rows from
the left table, and the matched rows from the right table
EG : view Table 1’s +
Intersection (matching data in two tables)
of two table’s data
Syn: SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name;
RIGHT JOIN: Return
all rows from the right table, and the matched rows from the left table
EG : Intersection (matching data in two tables) of
two table’s data + Table 2’s
FULL JOIN: Return all
rows when there is a match in ONE of the tables
EG : view complete 2 table’s data (Table1
+ Table 2)
for more details https://www.javatpoint.com/dbms-normalization