COMING SOON 🚀

SQL Basics - Primary Key

· 6년 전 · 804

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

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);

 

첨부파일

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

그누5튜닝

+
제목 글쓴이 날짜 조회
6년 전 조회 1,386
6년 전 조회 1,358
6년 전 조회 3,279
6년 전 조회 1,470
6년 전 조회 1,475
6년 전 조회 1,507
6년 전 조회 1,081
6년 전 조회 849
6년 전 조회 958
6년 전 조회 1,061
6년 전 조회 1,330
6년 전 조회 904
6년 전 조회 756
6년 전 조회 988
6년 전 조회 805
6년 전 조회 574
6년 전 조회 720
6년 전 조회 667
6년 전 조회 672
6년 전 조회 612
6년 전 조회 1,238
6년 전 조회 1,806
6년 전 조회 1,549
6년 전 조회 810
6년 전 조회 786
6년 전 조회 1,464
6년 전 조회 699
7년 전 조회 895
7년 전 조회 1,164
10년 전 조회 3,307