Thêm khóa chính cho cột

Chào các bạn, mình vừa mới học CSDL được 2 ngày, mình viết code tạo bảng các kiểu nhưng mà khi viết mình quên thêm not null cho khóa chính, giờ muốn cập nhật not null thì phải viết câu lệnh gì ạ, cảm ơn các bạn đã giúp đỡ.

SQL server, khoá chính mặc định not null và luôn luôn là not null, không cần thông báo

nó vẫn không được bạn ơi

CREATE DATABASE ProductShipping
ON PRIMARY
	(NAME = ProductShipping,
	FILENAME = 'E:\SQLSever\ProductShipping.MDF',
	SIZE = 3MB,
	MAXSIZE = 200MB,
	FILEGROWTH = 10%)
LOG ON
	(NAME = ProductShipping_log,
	FILENAME = 'E:\SQLSever\ProductShipping_log.lDF',
	SIZE = 1MB,
	MAXSIZE = 200MB,
	FILEGROWTH = 10%)
use ProductShipping

create schema HR 
create schema Production
create schema Sales

create table HR.Employees
(
	ma int primary key not null,
	ho nvarchar(20) not null,
	ten nvarchar(10) not null,
	chucdanh nvarchar(30) not null,
	ongbaco nvarchar(25) not null,
	ngaysinh date not null
)

create table Production.Categories 
(
	mahanghoa int not null,
	tenhanghoa nvarchar(15),
	mota nvarchar(200)
)

create table Production.Suppliers
(
	manhacungcap int primary key not null,
	tencongty nvarchar(40) not null,
	tennguoilienhe nvarchar(30) not null,
	chucdanhnguoilienhe nvarchar(30) not null,
	diachi nvarchar(60) not null,
	thanhpho nvarchar(15) not null,
	khuvuc nvarchar(15) not null,
	mabuudien nvarchar(10) not null,
	quocgia nvarchar(15) not null,
	sodienthoai nvarchar(24) not null,
	soFax nvarchar(24) not null
)

create table Production.Products
(
	mahanghoa int primary key not null,
	tenhanghoa nvarchar(40) not null,
	manhacungcap int not null,
	maloaihanghoa int not null,
	dongia money not null,
	ngungcungcap bit not null,
)

create table Sales.Comtumers
(
	makhachhang int primary key not null,
	tencongty nvarchar(40) not null,
	tennguoilienhe nvarchar(30) not null,
	chucdanhnguoilienhe nvarchar(30) not null,
	diachi nvarchar(60) not null,
	thanhpho nvarchar(15) not null,
	khuvuc nvarchar(15) not null,
	mabuudien nvarchar(10) not null,
	quocgia nvarchar(15) not null,
	sodienthoai nvarchar(24) not null,
	soFax nvarchar(24) not null
)

create table Sales.Shippers
(
	macongtyvanchuyen int primary key not null,
	tencongty nvarchar(40),
	sodienthoai nvarchar(24)
)

create table Sales.Orders
(
	sodathang int primary key not null,
	makhachhang int not null,
	manhanvien int not null,
	ngaydathang datetime not null,
	ngaygiaohang datetime not null,
	ngayvanchuyen datetime not null,
	macongtyvanchuyen int not null, 
	chiphivanchuyen money not null,
	tenphuongtienvanchuyen nvarchar(40) not null,
	diachiden  nvarchar(60) not null,
	thanhphoden nvarchar(15) not null,
	khuvucden nvarchar(15) not null,
	mabuudienden nvarchar(10) not null,
	quocgiaden nvarchar(15) not null,
)

create table Sales.OrderDetails
(
	sodathang int primary key not null,
	madathang int not null,
	dongia money not null,
	soluong smallint not null,
	tilegiamgia numeric(4,3) not null
)

alter table Production.Categories 
add constraint PK_Categories primary key(mahanghoa)

mình thêm khóa chính cho cái bảng thứ 2 ý

Chịu, mình vẫn chạy bình thường. Vẫn add được PK:

Nhưng mà đoạn script của bạn phải có go sau mỗi dòng create schema mới chạy được

có dữ liêu trong bản rồi đúng không?

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?