sql
sql
database
[1] how to create a database-- “ create database database_name; ”
[4] how to enable read-only mode in database – alter database database_name read only =1;
//We can access the database but cannot change it.. like we cannot perform any task in it
Table:
[1] how to create a table in a database –
entity type, // entity are generally column names or attributes, and types are the return type.
entity type
);
example –
first_name varchar(50),
last_name varchar(50),
hire_date date
);
[2] how to see a table all entities in a table – “select * from table_name;”
after last_name;
values
values
Select
[1] for select all –
from employees;
select *
from employees
where last_name="jana";
select *
from employees
update employees
set
hourly_pay = 10.58,
hire_date = "2025-01-07"
where customer_id = 4;
delete a row --
my_date date,
my_time time,
my_date_time datetime
);
// insert rows [note – +1 used for tomorrow , -1 used for yesterday with function]
Unique:
create table products (
product_id int ,
price decimal(5, 3)
);
add constraint
unique( product_id );
Notnull:
Check:
Default:
primary key:
if we declare a column as the primary key then each value of that column should be
add constraint
amount decimal(5, 2) );
(1002 , 20.3),
(1005,52.6);
auto increament
foreign key:
// creation of a table with primary key
first_name VARCHAR(50),
last_name VARCHAR(50)
);
("Larry", "Lobster"),
("Bubble", "Bass");
customer_id INT,
Joins:
CREATE TABLE Customers (
first_name VARCHAR(50),
last_name VARCHAR(50),
age INT,
country VARCHAR(50)
);
item VARCHAR(50),
amount DECIMAL(10, 2),
customer_id INT,
);
-- join Customers and Orders tables with their matching fields customer_id
SELECT * /*Customers.customer_id, Orders.item*/
FROM Customers
ON Customers.customer_id = Orders.customer_id;
order by:
limit:
select * from table_name
limit 10;
union:
union is used to join two select statement