SQL Basics - Primary Key

· 6년 전 · 739

테이블을 전부 지우는 경우..

DROP TABLE customer.customer;

 

테이블을 다시 만듭니다.  mssql에서는 identity(1,1)

 

create table Customer.Customer

   Id int AUTO_INCREMENT PRIMARY KEY,
   FirstName varchar(50),
   LastName varchar(50),
   Age int,
   City varchar(50)
);

 

새로 Custom 데이타도 입력하고

 

insert into customer.customer (FirstName, LastName, Age, City) values  ('Joey', 'Blue', 40, 'Goddard');
insert into customer.customer (FirstName, LastName, Age, City) values  ('Barry', 'Bonds', 50, 'San Francisco');
insert into customer.customer (FirstName, LastName, Age, City) values  ('Mike', 'Schmidt', 60, 'KC');

 

Product 데이타도 입력하고

 

create table Customer.Products

   Id int AUTO_INCREMENT PRIMARY KEY,
   ProductName varchar(50)
);

 

alter table Customer.Products
add Price float;

 

insert into Customer.Products (ProductName, Price) values ('Baseball', 5.95);
insert into Customer.Products (ProductName, Price) values ('Bat', 195.99);

 

select * from Customer.Products;

 

Order 데이타도 만들고

 

create table Customer.Orders
(
    OrderID int auto_increment primary Key,
    OrderDate Datetime,
    CustomerID int,
    ProductID int
);

select * from customer.orders;
select * from customer.Products;
select * from customer.Customer;

 

지금 (GetDate대신에 now로.) Barry Bonds가 Bat를 샀다고 하면

insert into customer.Orders (OrderDate, CustomerID, ProductID) values (now(), 2, 2);

 

https://youtu.be/9Pzj7Aj25lw?list=PLD20298E653A970F8&t=1954

첨부파일

정규화.xlsx (9.7 KB) 1회 2019-06-22 00:20
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,299
6년 전 조회 1,256
6년 전 조회 3,190
6년 전 조회 1,378
6년 전 조회 1,383
6년 전 조회 1,402
6년 전 조회 997
6년 전 조회 788
6년 전 조회 901
6년 전 조회 1,002
6년 전 조회 1,266
6년 전 조회 805
6년 전 조회 681
6년 전 조회 913
6년 전 조회 740
6년 전 조회 514
6년 전 조회 657
6년 전 조회 606
6년 전 조회 598
6년 전 조회 549
6년 전 조회 1,173
6년 전 조회 1,726
6년 전 조회 1,438
6년 전 조회 730
6년 전 조회 730
6년 전 조회 1,404
6년 전 조회 644
7년 전 조회 826
7년 전 조회 1,109
10년 전 조회 3,237
🐛 버그신고