T-SQL代码形成一个脚本:在test_db数据库中创建表p
时间: 2024-04-08 16:30:26 浏览: 107
在test_db数据库中创建表p的T-SQL代码如下:
```sql
USE test_db;
CREATE TABLE p (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);
```
请确认上述代码无误后,可以执行该脚本来创建表p。
相关问题
将下面任务中的T-SQL代码形成一个脚本:在test_db数据库中创建表person并插入如下元祖, 使用整型局部变量mycount统计person中的行数,并将其另命名为数据表中的行数。
Sure! Here's the T-SQL script to create the table "person" in the "test_db" database, insert the given tuples, and use a local integer variable "mycount" to count the number of rows in the "person" table and assign it to a variable named "row_count".
```sql
-- Create table "person"
USE test_db;
GO
CREATE TABLE person (
id INT,
name VARCHAR(50),
age INT
);
-- Insert tuples into "person" table
INSERT INTO person (id, name, age)
VALUES
(1, 'John', 25),
(2, 'Sarah', 30),
(3, 'Michael', 35);
-- Use local variable to count rows in "person" table
DECLARE @mycount INT;
SELECT @mycount = COUNT(*) FROM person;
-- Assign the row count to a variable named "row_count"
DECLARE @row_count INT;
SET @row_count = @mycount;
-- Display the row count
SELECT @row_count AS [Row Count];
```
Please note that this script assumes you have the necessary permissions to create a table and insert data into the database. Adjust the script accordingly if needed.
阅读全文