By GokiSoft.com|
14:59 20/11/2020|
SQL Server/MySQL
[Share Code] Bài giảng T2008A
Student
fisrt name
last name
address
phone
- Tao ra cau truc bang trong database nhu the nao
- Table (bang) => Student (chuan dat ten: a-zA-Z0-9 hoac _)
fisrt name => firstname: kieu du lieu => string => nvarchar(30)
last name => lastname: kieu du lieu => string => nvarchar(30)
address: string => nvarchar(200)
phone: string => nvarchar(15)
- Trien khai phat trien tren du an.
- dau tien : database => T2008A
Student2
firstname
lastname
address
phone
rollno: primary key => nvarchar(20)
Product
- id: int => tu tang => identity(1, 1)
- title => nvarchar(150)
- content => text
- thumbnail => nvarchar(500)
- amount => int => >= 0
- price => float => >= 0
- created_at & updated_at =>
------- Basic
create table Student(
firstname nvarchar(30),
lastname nvarchar(30),
address nvarchar(200),
phone nvarchar(20)
)
-- Them du lieu vao
insert into Student(firstname, lastname, address, phone)
values
('Diep', 'Tran Van', 'Nam Dinh', '123456789')
insert into Student(firstname, lastname, address, phone)
values
('A', 'Tran Van', 'Hai Duong', '123456789'),
('B', 'Tran Van', 'Ha Noi', '123456789')
select * from Student
-------- basic 1: primary key => khoa chinh => column => gia tri la duy nhat
create table Student2 (
rollno nvarchar(20) primary key,
firstname nvarchar(30),
lastname nvarchar(30),
address nvarchar(200),
phone nvarchar(20)
)
select * from Student2
insert into Student2(rollno, firstname, lastname, address, phone)
values
('R002', 'Diep', 'Tran Van', 'Nam Dinh', '123456789')
insert into Student2(rollno, firstname, lastname, address, phone)
values
('R003', '', '', '', '')
insert into Student2(rollno, firstname, lastname, address, phone)
values
('', 'Diep', 'Tran Van', 'Nam Dinh', '123456789')
----- error chuong trinh
insert into Student2(rollno, firstname, lastname, address, phone)
values
(null, 'Diep', 'Tran Van', 'Nam Dinh', '123456789')
------ basic 2 - nang cao
create table Product (
id int primary key identity(1,1),
title nvarchar(150) not null,
content text,
amount int,
price float
)
alter table Product
add created_at datetime;
alter table Product
add updated_at datetime
alter table Product
add abc datetime
select * from Product
alter table Product
drop column abc
alter table Product
add constraint check_amount check (amount >= 0)
alter table Product
add constraint check_price check (price >= 0)
insert into Product(title, amount, price, created_at, updated_at)
values
('A', 1, 10, '2020-08-22 10:5:30', '2020-08-22 10:5:30')
delete from Product
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)